From a94e4ae74bc8470772e5e69904db7287a44a6d2a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 04:35:16 +0000 Subject: [PATCH 001/140] Auto-generated commit f030017f3bbf3091e550138090a4b60e4fb56898 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 250 +++++ index.d.ts | 53 + index.mjs | 4 + index.mjs.map | 1 + package.json | 41 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3548 insertions(+) create mode 100644 CONTRIBUTORS create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 package.json create mode 100644 stats.html diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..e5c896d --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,28 @@ +# This file is generated by tools/scripts/update_contributors. +# +# Contributors listed in alphabetical order. + +Ali Salesi +Athan Reines +Brendan Graetz +Bruno Fenzl +Christopher Dambamuromo +Dominik Moritz +Frank Kovacs +James +Jithin KS +Joey Reed +Joris Labie +Justin Dennison +Marcus +Matt Cochrane +Milan Raj +Momtchil Momtchev +Ognjen Jevremović +Philipp Burckhardt +Ricky Reusser +Ryan Seal +Seyyed Parsa Neshaei +Shraddheya Shendre +dorrin-sot <59933477+dorrin-sot@users.noreply.github.com> +rei2hu diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fcc9934 --- /dev/null +++ b/LICENSE @@ -0,0 +1,481 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: + +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES +OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + + +DEPENDENCIES + +The library links against the following external libraries, which have their own +licenses: + +* OpenBLAS + +Copyright (c) 2011-2014, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* Electron + +Copyright (c) 2013-2017 GitHub Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* Boost + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +* Cephes + +Copyright (c) 1984-2000 Stephen L. Moshier + +Some software in this archive may be from the book _Methods and Programs for +Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) +or from the Cephes Mathematical Library, a commercial product. In either event, +it is copyrighted by the author. What you see here may be used freely but it +comes with no support or guarantee. + +Stephen L. Moshier +moshier@na-net.ornl.gov + + + +ATTRIBUTION + +The library contains implementations from the following external libraries, +which have their own licenses: + +* FreeBSD + +Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* FDLIBM + +Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* Go + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* SLATEC Common Mathematical Library + +Public domain. + + +* ESLint + +Copyright JS Foundation and other contributors, https://js.foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +* StatsFuns.jl + +Copyright (c) 2015: Dahua Lin. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* SpecialFunctions.jl + +The MIT License (MIT) + +Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others: + +https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +* MT19937 + +Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..10e6ba1 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +Copyright (c) 2016-2022 The Stdlib Authors. diff --git a/README.md b/README.md new file mode 100644 index 0000000..99aa823 --- /dev/null +++ b/README.md @@ -0,0 +1,250 @@ + + +# vind2bind + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Convert a linear index in an array view to a linear index in an underlying data buffer. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +``` + +#### vind2bind( shape, strides, offset, order, idx, mode ) + +Converts a linear index in an array view to a linear index in an underlying data buffer. + +```javascript +var shape = [ 3, 3 ]; +var order = 'row-major'; +var strides = [ -3, 1 ]; +var offset = 6; + +var idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); +// returns 7 +``` + +The function supports the following `modes`: + +- `throw`: specifies that the function should throw an error when a linear index exceeds array dimensions. +- `wrap`: specifies that the function should wrap around a linear index exceeding array dimensions using modulo arithmetic. +- `clamp`: specifies that the function should set a linear index exceeding array dimensions to either `0` (minimum linear index) or the maximum linear index. + +```javascript +var shape = [ 2, 2 ]; +var order = 'row-major'; +var strides = [ -2, 1 ]; +var offset = 2; + +var idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); +// returns 0 + +idx = vind2bind( shape, strides, offset, order, 10, 'clamp' ); +// returns 1 +``` + +The `order` parameter specifies whether an array is `row-major` (C-style) or `column-major` (Fortran-style). + +```javascript +var shape = [ 2, 2 ]; +var order = 'column-major'; +var strides = [ 1, -2 ]; +var offset = 2; + +var idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); +// returns 0 +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```html + + + + + + +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + +
+ +* * * + +## Notice + +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. + +For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. + +#### Community + +[![Chat][chat-image]][chat-url] + +--- + +## License + +See [LICENSE][stdlib-license]. + + +## Copyright + +Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. + +
+ + + + + + + + diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..bbf7396 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,53 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { Mode, Order } from '@stdlib/types/ndarray'; + +/** +* Converts a linear index in an array view to a linear index in an underlying data buffer. +* +* @param shape - array shape +* @param strides - stride array +* @param offset - location of the first indexed value **based** on the stride array +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param idx - linear index in an array view +* @param mode - specifies how to handle a linear index which exceeds array dimensions +* @throws linear index must not exceed array dimensions +* @returns linear index in an underlying data buffer +* +* @example +* var shape = [ 3, 3 ]; +* var strides = [ -3, 1 ]; +* var offset = 6; +* var order = 'row-major'; +* var mode = 'throw'; +* +* var ind = vind2bind( shape, strides, offset, order, 1, mode ); +* // returns 7 +*/ +declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length + + +// EXPORTS // + +export = vind2bind; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a0ee03d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var e=r;var n=function(r,n,a,t,i,o){var s,m,f,l,d;for(s=r.length,m=1,d=0;d=m&&(i=m-1);else if("wrap"===o)i<0?(i+=m)<0&&0!==(i%=m)&&(i+=m):i>=m&&(i-=m)>=m&&(i%=m);else if(i<0||i>=m)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",m,i));if(f=a,"column-major"===t){for(d=0;d=0;d--)i-=l=i%r[d],i/=r[d],f+=l*n[d];return f};export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..24349dc --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"],"names":["format","require$$0","lib","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError"],"mappings":";;iFAsBA,IAAIA,EAASC,EAuFb,IChEAC,EDIA,SAAoBC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYf,EAAQ,gHAAiHU,EAAKH,IAIrJ,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..df0934b --- /dev/null +++ b/package.json @@ -0,0 +1,41 @@ +{ + "name": "@stdlib/ndarray-base-vind2bind", + "version": "0.0.0", + "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/ndarray-base-vind2bind.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", + "view", + "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..28fb2b1 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From b276136e2e2e4b56b80549b3da3378fff93b7f58 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 23:13:44 +0000 Subject: [PATCH 002/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 67be20d..e260a69 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 2b7f32654f46cf516f94a2ac4fc3cf648b7c877b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 10:38:14 +0000 Subject: [PATCH 003/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2747 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a0ee03d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var e=r;var n=function(r,n,a,t,i,o){var s,m,f,l,d;for(s=r.length,m=1,d=0;d=m&&(i=m-1);else if("wrap"===o)i<0?(i+=m)<0&&0!==(i%=m)&&(i+=m):i>=m&&(i-=m)>=m&&(i%=m);else if(i<0||i>=m)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",m,i));if(f=a,"column-major"===t){for(d=0;d=0;d--)i-=l=i%r[d],i/=r[d],f+=l*n[d];return f};export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 24349dc..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"],"names":["format","require$$0","lib","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError"],"mappings":";;iFAsBA,IAAIA,EAASC,EAuFb,IChEAC,EDIA,SAAoBC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYf,EAAQ,gHAAiHU,EAAKH,IAIrJ,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 28fb2b1..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a9e30bc797b858fef3aab0ca92869ed3f8d9a2ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 10:39:01 +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 | 41 +- benchmark/benchmark.js | 424 ---- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 600 ----- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 -- examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5330 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 3f53b6e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T21:26:37.216Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e2cd0c8..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7c92a8a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d620926 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;0FAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e260a69..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f2cdc24 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 3ef3a6bc3a13184a7647b07c293b075d2a5ca54d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:48:06 +0000 Subject: [PATCH 005/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 67be20d..e260a69 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 ca0b24c5f6745e27a56973eadbfb55a17178e400 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 09:21:44 +0000 Subject: [PATCH 006/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2747 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7c92a8a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d620926..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;0FAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f2cdc24..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e4f82b92257deb8375bcc610a7890009ba1952ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 09:22:32 +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 | 41 +- benchmark/benchmark.js | 424 ---- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 600 ----- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 -- examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5330 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 892f144..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T00:46:36.351Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e2cd0c8..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7c92a8a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d620926 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;0FAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e260a69..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0374af8 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From c10672c0da349fbcc64f7d61f46fdb01cf44a818 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 16:49:36 +0000 Subject: [PATCH 008/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 67be20d..e260a69 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 fe7c44739adbda39fb6b26d850da2888ced71ec9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 16:50:55 +0000 Subject: [PATCH 009/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2747 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7c92a8a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d620926..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;0FAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0374af8..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 30746f93c0aee7136f7717dd6bf31bba112c1066 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 16:51:59 +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 | 41 +- benchmark/benchmark.js | 424 ---- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 600 ----- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 -- examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 41 files changed, 2714 insertions(+), 5295 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e2cd0c8..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7c92a8a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d620926 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;0FAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e260a69..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2149595 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 69af667d1b6faf86022f2475702087ae20c91001 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:36:23 +0000 Subject: [PATCH 011/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 67be20d..e260a69 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 0ed1e337bd64ab20815dc7621590bbc1cbb91e51 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 10:42:11 +0000 Subject: [PATCH 012/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2747 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7c92a8a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d620926..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;0FAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2149595..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 3b8fa899f21eb8945549da9ddebd29f5c06b263a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 10:43:02 +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 | 41 +- benchmark/benchmark.js | 424 ---- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 600 ----- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 -- examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5369 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 c2cd1db..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T00:49:52.789Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e2cd0c8..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87f7ec6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3fb12dd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e260a69..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5938f9e --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From f48b94c740d841984b79c370baf975701f675f39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:19:41 +0000 Subject: [PATCH 014/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 67be20d..e260a69 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 56a0ba4ac14595b0efabb13092470e245ab9d54c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:10:42 +0000 Subject: [PATCH 015/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2747 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87f7ec6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3fb12dd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5938f9e..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 00a04424aea1d56684832f36ae17d5d8b002c2da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:11:33 +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 | 41 +- benchmark/benchmark.js | 424 ---- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 600 ----- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 -- examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5385 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 5d42658..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T00:45:42.832Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e2cd0c8..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87f7ec6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3fb12dd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e260a69..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8a17370 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 700307b52506550c73430d7659e0fd648ff1729c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 03:38:15 +0000 Subject: [PATCH 017/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 67be20d..e260a69 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 3cb0508813e5a8e522ee742d270d74b491a916e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 17:38:35 +0000 Subject: [PATCH 018/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2747 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87f7ec6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3fb12dd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8a17370..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 88840caec1f87949e87b13a0e95d3589592a40e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 17:39:22 +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 | 41 +- benchmark/benchmark.js | 424 ---- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 600 ----- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 -- examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5385 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 bea5733..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:10:09.186Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87f7ec6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3fb12dd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e260a69..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ff9063a --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From e2ff477299f6a641d1a85f32987d272c65dcd24f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:24:07 +0000 Subject: [PATCH 020/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 67be20d..e260a69 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 cea5f5e7364e44ed6922bc3055e1ecce23495e5f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 13:52:22 +0000 Subject: [PATCH 021/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2747 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87f7ec6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3fb12dd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,EAGR,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ff9063a..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e6b5bebfdeec0326bf8a78ccae1e979430d5e803 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 13:53:17 +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 | 41 +- benchmark/benchmark.js | 424 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 --- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 4044 +++++++++++++++++++++ test/test.js | 577 --- 42 files changed, 4069 insertions(+), 5385 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 5ee7b11..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T00:56:36.648Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87f7ec6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0a0ecbe --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e260a69..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..16743d0 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From d645ebf0b57c1d17a01526ec6225cdd74d977122 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 23:41:43 +0000 Subject: [PATCH 023/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 67be20d..e260a69 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 f1ebdf8f367fe77f5c6ea624acb43721cf11c713 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 06:53:26 +0000 Subject: [PATCH 024/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4102 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87f7ec6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0a0ecbe..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 16743d0..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 3658b1a5c1ac74ced7dc6d8aa7f30e0c0f30dbca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 06:54:12 +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 | 41 +- benchmark/benchmark.js | 424 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 --- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 4044 +++++++++++++++++++++ test/test.js | 577 --- 42 files changed, 4069 insertions(+), 5406 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 ebd9962..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T21:08:04.485Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87f7ec6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0a0ecbe --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e260a69..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..bd6749f --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 263af3a0d2e88abafe7119615c777e0407fd062d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 03:22:40 +0000 Subject: [PATCH 026/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index d80f63f..b791643 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 8337f9982af1cf21a91fa8ef7f20197cbb17d44c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 10:29:32 +0000 Subject: [PATCH 027/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4102 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87f7ec6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0a0ecbe..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bd6749f..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From bdf9c2c94630c3eb76b33378748779b6d95fd3dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 10:30:27 +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 | 41 +- benchmark/benchmark.js | 424 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 --- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 4044 +++++++++++++++++++++ test/test.js | 577 --- 42 files changed, 4069 insertions(+), 5411 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 260bcc3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T00:58:28.365Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87f7ec6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8549543 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index b791643..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3969e90 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From ede954b9f97a2b3aa0038617f76b400e1ea00c0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 03:15:26 +0000 Subject: [PATCH 029/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 317ce52..e003607 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 70394fb78435bb1aeb2aa795b547c3b2c3e71d89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 13:10:25 +0000 Subject: [PATCH 030/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4102 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87f7ec6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8549543..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3969e90..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From dafb012b3832fa8c5078ac665afe1a92d243b31b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 13:11:22 +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 | 41 +- benchmark/benchmark.js | 424 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 --- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 4044 +++++++++++++++++++++ test/test.js | 577 --- 42 files changed, 4069 insertions(+), 5422 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 83a9591..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T00:45:49.540Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8f93041 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e3603f1 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;0FAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e003607..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3c0ca93 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 3c446b0f7d4c1403735799ecc282c69102c40dd0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:28:29 +0000 Subject: [PATCH 032/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 317ce52..e003607 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^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 4ca056a4b6f62fa4a7afa0b10b59b0022e30990f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 08:26:29 +0000 Subject: [PATCH 033/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4102 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8f93041..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e3603f1..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;0FAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3c0ca93..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From afed90f91449864cf489c89fabfae635973c1b08 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 08:27:21 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5422 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 2b3fd67..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T00:55:04.906Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 33ff96b..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/vind2bind" -click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..947a34b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8549543 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index e003607..3913224 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cb93697 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 7b46b30f4521b4f10f428a9117f6634e702a23a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 02:20:09 +0000 Subject: [PATCH 035/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 755db68..2aa220f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^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 7e2ea18dcb37c341c7f20d04e7149930088956b9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:37:59 +0000 Subject: [PATCH 036/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 947a34b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8549543..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cb93697..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6611d940d58dd26af0aa3aa3f769425b822c72af Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:38:55 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5557 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 6c8653e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T01:33:08.845Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..947a34b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8549543 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 2aa220f..06edf33 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e95ff8d --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 10be30baf7ed1dfa11a82f465cc9b0c7a26813a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 02:21:53 +0000 Subject: [PATCH 038/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 755db68..2aa220f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^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 a7bbc1d13a8413cc53a0376a3c7ccf1ad007f629 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 05:26:39 +0000 Subject: [PATCH 039/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 947a34b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8549543..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e95ff8d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 73aa7af5d60065decfce8d2f6d5afbcbae5f3ade 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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5563 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 1d4a743..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T01:39:05.380Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..947a34b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8549543 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 2aa220f..06edf33 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..10ebd3f --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From e733e432f22c6b4679480903c0d66bbe2b4ee662 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 02:17:45 +0000 Subject: [PATCH 041/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 755db68..2aa220f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^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 f05972e84e7ee8f699f0925563bcac458d757b4e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 05:11:08 +0000 Subject: [PATCH 042/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 947a34b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8549543..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 10ebd3f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 36e708f879e9e664ba6682aa57e996b150c2ac02 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 05:12:02 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5563 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 7a15791..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T01:35:56.246Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..947a34b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8549543 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 2aa220f..06edf33 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d3153cf --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 9d4ff0a7a1e471b9945acbe08612567619f30fd5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 02:19:02 +0000 Subject: [PATCH 044/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 755db68..2aa220f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^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 12cd5872d3c04aa6bf0e824d51238dd68e811a18 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:27:53 +0000 Subject: [PATCH 045/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 947a34b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8549543..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d3153cf..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 00bc6d3560ffb30e6ecf3fbf3d12a42f933f6e3b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:28:49 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5563 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 e21f5b4..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T01:36:11.574Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..947a34b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8549543 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 2aa220f..06edf33 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..687974c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 4c839a7cff9057aabb15f1ed73469f905924f50c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 02:18:49 +0000 Subject: [PATCH 047/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 755db68..2aa220f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^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 c9179c8bc4f7f64ad255efed4d11fae86f8fc8d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:32:30 +0000 Subject: [PATCH 048/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 947a34b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8549543..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 687974c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e178e11ac4883bedec8f911c91142a02f56068fc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:33:28 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5563 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 f540de6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T01:36:27.234Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..947a34b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8549543 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 2aa220f..06edf33 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2cd6ce1 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 64cb1b0459eb0340c19e8c7b8a4c0de409096ad5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 02:27:16 +0000 Subject: [PATCH 050/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 a117229..6525bef 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0Mk5S', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 755db68..2aa220f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^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 8212ccae155890e9fc8e1688fbf6cf65fc1c550d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 05:35:44 +0000 Subject: [PATCH 051/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 947a34b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8549543..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2cd6ce1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7c29065af9143f6c4d339f1c2b3a66113a42485a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 05:36:35 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5563 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 7ebde42..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T01:39:13.444Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -193,7 +186,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 2e6a6dd..bbf7396 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..947a34b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8549543 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 6525bef..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0Mk5S', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 2aa220f..06edf33 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.8", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2962143 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From f2fc59fadbd369e608e9f735841ede919edaab2e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:10:41 +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 a117229..417bd4e 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E,L1', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 9998b08..bc37dd2 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.0", "@stdlib/ndarray-orders": "^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 efd568953b272b222f88eb09f03f46f17d33d26e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:46:17 +0000 Subject: [PATCH 054/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index bbf7396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 947a34b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0Mk5S",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8549543..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0Mk5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAI7C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2962143..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f00b0ee2f9f551146b22b7fc6a32e4ca12d05138 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:47:21 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 45 files changed, 6202 insertions(+), 5597 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f7d1c3c..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fc0a1ac..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: '23 11 * * 4' - - # 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 + + ```
@@ -204,7 +197,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index daa63ba..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 66cffc2..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAGEH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,ICrEjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 702bc73..861f309 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a55b29b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7b3390f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 417bd4e..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E,L1', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index bc37dd2..d08d8dd 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.0", - "@stdlib/ndarray-orders": "^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-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..81588ff --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 4e89ae4bafff8088bac2776461367a57236e56b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 00:07:27 +0000 Subject: [PATCH 056/140] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 37bf727..fa0f9e2 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs'; ``` #### vind2bind( shape, strides, offset, order, idx, mode ) @@ -130,7 +130,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From a292bee72e3695e6915ef434fc73f2a9ba665160 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 00:07:29 +0000 Subject: [PATCH 057/140] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fa0f9e2..d40062e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-vind2bind/tags). For example, + ```javascript import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs'; ``` @@ -130,7 +135,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 25364a2e88994116b3b1907b6151057ef1e3d4e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 02:46:49 +0000 Subject: [PATCH 058/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 a117229..417bd4e 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E,L1', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index cd609eb..6f973e1 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.0", "@stdlib/ndarray-orders": "^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 7ae83709f01df69ffc6ee7a0bbeac705ff851325 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 20:30:49 +0000 Subject: [PATCH 059/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 861f309..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a55b29b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b3390f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 81588ff..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2d00f0683abb909f54338394c12d1f2b828d8077 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 20:34:14 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 577 -- test/test.js | 577 -- 47 files changed, 6202 insertions(+), 6233 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 0bfdb3e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T01:21:06.045Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d9938f1..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: '23 11 * * 4' - - # 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 + + ```
@@ -204,7 +197,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index daa63ba..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 66cffc2..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAGEH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,ICrEjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 702bc73..861f309 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a55b29b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7b3390f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 417bd4e..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E,L1', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 6f973e1..d08d8dd 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.0", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..663119a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8a6add3..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From a4b87b5284ec3ad3e4179a2cb4abd94bcf0d30d7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 02:26:50 +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 a117229..417bd4e 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E,L1', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 6107bd4..c5976d1 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^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 7c80e58fad4162b6983d5f32519bda62c636bfa0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 11:22:16 +0000 Subject: [PATCH 062/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 861f309..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a55b29b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b3390f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 663119a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0a638136bae73a61a86fe9bd2e03f51b38a0faa8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 11:25:45 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 577 -- test/test.js | 577 -- 46 files changed, 6202 insertions(+), 6232 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d9938f1..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: '23 11 * * 4' - - # 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 + + ```
@@ -204,7 +197,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index daa63ba..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 66cffc2..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAGEH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,ICrEjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 702bc73..861f309 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..637bf57 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7b3390f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 417bd4e..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E,L1', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index c5976d1..cefbbc1 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b1bc8a9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8a6add3..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 2e9d06e9826339809590a1ec2d34912260781780 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 15:43:43 +0000 Subject: [PATCH 064/140] Update README.md for ESM bundle v0.1.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4110dd..7d959f6 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs'; ``` #### vind2bind( shape, strides, offset, order, idx, mode ) @@ -130,7 +130,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 222c03a05e3e239384de95a0d82a268f35cd7e0b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 15:43:44 +0000 Subject: [PATCH 065/140] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d959f6..b8ad80d 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-vind2bind/tags). For example, + ```javascript import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs'; ``` @@ -130,7 +135,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From de351446f4cbd00395113a82738e6db3cf316cf1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 04:54:51 +0000 Subject: [PATCH 066/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 a117229..417bd4e 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E,L1', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 1f929d4..7747d35 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^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 3c36e69fe5e4f122eea8674757580f7e3da0321f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 22:45:15 +0000 Subject: [PATCH 067/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 861f309..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 637bf57..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b3390f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b1bc8a9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e747781a4e16767ac04025584587abdf5bdb761f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 22:47:56 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 577 -- test/test.js | 577 -- 46 files changed, 6202 insertions(+), 6232 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d9938f1..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: '23 11 * * 4' - - # 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 + + ```
@@ -204,7 +197,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index daa63ba..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 66cffc2..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAGEH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,ICrEjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 702bc73..861f309 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..637bf57 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7b3390f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 417bd4e..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E,L1', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 7747d35..cefbbc1 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ddb2cee --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8a6add3..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From e20453ed3397a123b62599b3812046e5c77f4cac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 02:49:17 +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 a117229..417bd4e 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 // @@ -81,7 +81,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { } } } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E,L1', len, idx ) ); } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... ind = offset; diff --git a/package.json b/package.json index 8792cc4..46f9033 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^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 e03f2f40fc8cdc508ab5c754bf021acb94659684 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 20:53:32 +0000 Subject: [PATCH 070/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 861f309..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 637bf57..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b3390f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ddb2cee..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6a2739d5862d55421728391dc427dec0ddea60ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 20:56:07 +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 | 41 +- benchmark/benchmark.js | 424 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 600 -- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 48 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 110 - manifest.json | 41 - package.json | 64 +- src/main.c | 106 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 577 -- 47 files changed, 6202 insertions(+), 5697 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 ed84bd7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T01:21:58.090Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d9938f1..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: '23 11 * * 4' - - # 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 + + ```
@@ -204,7 +197,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index aa638c5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,424 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== 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 8be7ec5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,600 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12() { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index daa63ba..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 66cffc2..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAGEH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,ICrEjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3b466e6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'wrap', the function wraps around - a linear index exceeding array dimensions using modulo arithmetic. If - equal to 'clamp', the function sets a linear index exceeding array - dimensions to either `0` (minimum linear index) or the maximum linear - index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef21bf8..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 702bc73..861f309 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..637bf57 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7b3390f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 417bd4e..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E,L1', len, idx ) ); - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 46f9033..cefbbc1 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 d7d1ab9..0000000 --- a/src/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" mode, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C - if ( idx != 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else if ( idx < 0 || idx >= len ) { - return -1; - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; // assume nonnegative "shape" - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..27e231d --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index abd362b..0000000 --- a/test/test.js +++ /dev/null @@ -1,577 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 6134f92ea92c8a1b7c3450ed9a646e39ee5c6b2b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:29:00 +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 4177905..a7f9f4f 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E,L1', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 0f015d7..f139b93 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^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 ef3f08adc7f5b43c2d47571e94801094f98760ea Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:31:03 +0000 Subject: [PATCH 073/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 861f309..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 637bf57..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if(n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b3390f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else if ( idx < 0 || idx >= len ) {\n\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAGH,GAAKH,EAAM,GAAKA,GAAOG,EAC7B,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAIhD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 27e231d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c64bfaff4aa2ca962dd9b39113cc863bed7930e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:33:31 +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 | 41 +- benchmark/benchmark.js | 554 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 64 +- src/main.c | 113 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 46 files changed, 6202 insertions(+), 6136 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d9938f1..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: '23 11 * * 4' - - # 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 + + ```
@@ -205,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 102f467..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..36d97b3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..11af41d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAKjD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a7f9f4f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E,L1', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index f139b93..cefbbc1 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1813ec1 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 2a2a5ba40427a74974b7d49f495dbcd463400435 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 02:43:11 +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 4177905..a7f9f4f 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E,L1', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 0f015d7..f139b93 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^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 14879eda3ee7fe78ad2a1f936eec6d8eb707c12a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:24:31 +0000 Subject: [PATCH 076/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 36d97b3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 11af41d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAKjD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1813ec1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8f175806566b59f00456a2d130cdc939a3f1eb0c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:27:00 +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 | 41 +- benchmark/benchmark.js | 554 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 64 +- src/main.c | 113 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 47 files changed, 6202 insertions(+), 6137 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 fb350ef..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T01:26:25.895Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d9938f1..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: '23 11 * * 4' - - # 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 + + ```
@@ -205,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 102f467..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..36d97b3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..11af41d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAKjD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a7f9f4f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E,L1', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index f139b93..cefbbc1 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..04f75db --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 68b043cc9428790130957f412d9fd7d275934bb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 02:04:09 +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 da0fa57..c9803a4 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^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 0641ba45d2cba1a1d454a03a80306da7b808d3a5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:41:25 +0000 Subject: [PATCH 079/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 36d97b3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E,L1",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 11af41d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E,L1', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,WAAYN,EAAKH,IAKjD,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 04f75db..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 028622613d013192822001b3a8d210c864e73c40 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:41:46 +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 | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 64 +- src/main.c | 113 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 6202 insertions(+), 6143 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 3f60b94..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T01:19:23.195Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 5603f6a..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: '23 11 * * 4' - - # 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 + + ```
@@ -205,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index cdee7ca..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ad4a4f8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function r(r,n,t,a,i,o){var m,s,f,l,d;for(m=r.length,s=1,d=0;d=s&&(i=s-1);else if("wrap"===o)i<0?(i+=s)<0&&0!==(i%=s)&&(i+=s):i>=s&&(i-=s)>=s&&(i%=s);else if("normalize"===o&&i<0&&(i+=s),i<0||i>=s)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,i));if(f=t,"column-major"===a){for(d=0;d=0;d--)i-=l=i%r[d],i/=r[d],f+=l*n[d];return f}export{r as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d7d6622 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;wFAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,gHAAiHN,EAAKH,IAKtJ,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4177905..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index c9803a4..cefbbc1 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d185110 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 48b904e49e5a7d9a8ed66263d172a159f09fc904 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 02:06:22 +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 da0fa57..c9803a4 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^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 4ad8ae1a36096f35aabebdd70e0b6605c8308f44 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:35:01 +0000 Subject: [PATCH 082/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ad4a4f8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function r(r,n,t,a,i,o){var m,s,f,l,d;for(m=r.length,s=1,d=0;d=s&&(i=s-1);else if("wrap"===o)i<0?(i+=s)<0&&0!==(i%=s)&&(i+=s):i>=s&&(i-=s)>=s&&(i%=s);else if("normalize"===o&&i<0&&(i+=s),i<0||i>=s)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,i));if(f=t,"column-major"===a){for(d=0;d=0;d--)i-=l=i%r[d],i/=r[d],f+=l*n[d];return f}export{r as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d7d6622..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;wFAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,gHAAiHN,EAAKH,IAKtJ,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d185110..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2d9dfa3c131bbaf5cd6db0f6e83d82fa3f7c0d37 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:35:31 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 64 +- src/main.c | 113 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 6202 insertions(+), 6148 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 96662dc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T01:27:18.725Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 5603f6a..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ad4a4f8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function r(r,n,t,a,i,o){var m,s,f,l,d;for(m=r.length,s=1,d=0;d=s&&(i=s-1);else if("wrap"===o)i<0?(i+=s)<0&&0!==(i%=s)&&(i+=s):i>=s&&(i-=s)>=s&&(i%=s);else if("normalize"===o&&i<0&&(i+=s),i<0||i>=s)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,i));if(f=t,"column-major"===a){for(d=0;d=0;d--)i-=l=i%r[d],i/=r[d],f+=l*n[d];return f}export{r as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d7d6622 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;wFAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,gHAAiHN,EAAKH,IAKtJ,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4177905..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index c9803a4..cefbbc1 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..62385b8 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 31df16ecabf3e97ca05f6d7fcb544b06f4bc8227 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 05:06:41 +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 0fc5e9e..d1dafe4 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.0", "@stdlib/ndarray-orders": "^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 73702c868273c06362193203511d521d9738d3c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 07:37:44 +0000 Subject: [PATCH 085/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ad4a4f8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function r(r,n,t,a,i,o){var m,s,f,l,d;for(m=r.length,s=1,d=0;d=s&&(i=s-1);else if("wrap"===o)i<0?(i+=s)<0&&0!==(i%=s)&&(i+=s):i>=s&&(i-=s)>=s&&(i%=s);else if("normalize"===o&&i<0&&(i+=s),i<0||i>=s)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,i));if(f=t,"column-major"===a){for(d=0;d=0;d--)i-=l=i%r[d],i/=r[d],f+=l*n[d];return f}export{r as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d7d6622..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;wFAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,gHAAiHN,EAAKH,IAKtJ,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 62385b8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 82efc96dbca7acc509910d83148cfff908310246 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 07:38:12 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 64 +- src/main.c | 113 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 47 files changed, 6202 insertions(+), 6151 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 0cc83a1..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ad4a4f8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function r(r,n,t,a,i,o){var m,s,f,l,d;for(m=r.length,s=1,d=0;d=s&&(i=s-1);else if("wrap"===o)i<0?(i+=s)<0&&0!==(i%=s)&&(i+=s):i>=s&&(i-=s)>=s&&(i%=s);else if("normalize"===o&&i<0&&(i+=s),i<0||i>=s)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,i));if(f=t,"column-major"===a){for(d=0;d=0;d--)i-=l=i%r[d],i/=r[d],f+=l*n[d];return f}export{r as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d7d6622 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;wFAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,gHAAiHN,EAAKH,IAKtJ,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4177905..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index d1dafe4..9711442 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.0", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.0", - "@stdlib/ndarray-orders": "^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-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..47c06da --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From c56162b2b0226e5c63eaa22981230268288fae7d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 10:46:19 +0000 Subject: [PATCH 087/140] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab08c2e..29f7bb1 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.0-esm/index.mjs'; ``` #### vind2bind( shape, strides, offset, order, idx, mode ) @@ -131,7 +131,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.0-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 3d397dcb859bc18da929eb8fb6d7e3e253146fae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 10:46:19 +0000 Subject: [PATCH 088/140] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 29f7bb1..cb0d786 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-vind2bind/tags). For example, + ```javascript import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.0-esm/index.mjs'; ``` @@ -131,7 +136,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.0-esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 2f8693993b9b4968f94b6c56b6282e0122f0968d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 02:11:55 +0000 Subject: [PATCH 089/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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 8c7f74d..c14dd2a 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^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" }, From 71d08a43c49786c78fe091eb5e161598117c377a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:32:51 +0000 Subject: [PATCH 090/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6235 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ad4a4f8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function r(r,n,t,a,i,o){var m,s,f,l,d;for(m=r.length,s=1,d=0;d=s&&(i=s-1);else if("wrap"===o)i<0?(i+=s)<0&&0!==(i%=s)&&(i+=s):i>=s&&(i-=s)>=s&&(i%=s);else if("normalize"===o&&i<0&&(i+=s),i<0||i>=s)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,i));if(f=t,"column-major"===a){for(d=0;d=0;d--)i-=l=i%r[d],i/=r[d],f+=l*n[d];return f}export{r as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d7d6622..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;wFAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,gHAAiHN,EAAKH,IAKtJ,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 47c06da..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From df29d31ccb8f5e13b3c2d9c4e3db6c40921f0862 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:34:12 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 64 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 47 files changed, 4867 insertions(+), 6145 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a73fd9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index c14dd2a..d5b5373 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^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-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", @@ -93,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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6c93b4e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From a4b5401f11cd1f5bfa96e3f899d1173f44d3d601 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:54:54 +0000 Subject: [PATCH 092/140] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 827c464..5641170 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs'; ``` #### vind2bind( shape, strides, offset, order, idx, mode ) @@ -131,7 +131,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From ab392d063fd0dcb7d6cdd1d32f79474629348f5a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:54:54 +0000 Subject: [PATCH 093/140] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5641170..9d8097e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-vind2bind/tags). For example, + ```javascript import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs'; ``` @@ -131,7 +136,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 740e9b56782d13b6a131e9103f8a6bd1330b8b1f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 01:53:39 +0000 Subject: [PATCH 094/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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 3ee75da..d32d3f6 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^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 305f6332d4bb6a3d3367e4f39625926a45d52eb2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 03:37:31 +0000 Subject: [PATCH 095/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a73fd9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6c93b4e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 74b6b93e61645af969838247f71a55f9463b7edd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 03:37:49 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6148 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 f487a83..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T01:27:20.135Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a73fd9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index d32d3f6..d5b5373 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6c93b4e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From c3d233d340dfc2b76a243eeb8ebbdf2d86f53358 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 01:43:39 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 2642242..0b6cca8 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^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 49793c79b046bf2aec4ec28a3128a099d0cb6bae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:44:52 +0000 Subject: [PATCH 098/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a73fd9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6c93b4e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 94dbe3efb9b27f9bd0bb63b94bb2c4f3f4fe0b21 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:45:04 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6151 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 b08fe88..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T01:15:05.787Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a73fd9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 0b6cca8..d5b5373 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6c93b4e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From f5fa49417dbf66f27335efd42e0706cd0c3f3e3c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 21:49:23 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 2642242..0b6cca8 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^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 1283b131e842fd92a01626ef2c7cb59d69ccc1ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:50:40 +0000 Subject: [PATCH 101/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a73fd9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6c93b4e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2016c3595ce1a7b34045eaea60d0a605cfe17d06 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:50:59 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 47 files changed, 4867 insertions(+), 6152 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a73fd9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 0b6cca8..d5b5373 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6c93b4e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From a9bcb9fce41690da05903473b25871789cf0b9f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 01:43:57 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 2642242..0b6cca8 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^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 e0dc18af3d20ffb90b2984bf5a3a8a877a64275e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:18:18 +0000 Subject: [PATCH 104/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a73fd9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6c93b4e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1aa63d4316925c6854cea2f2383a4f38c44fb906 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:18:37 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6160 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 5a5b2ba..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-05-01T01:15:51.662Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a73fd9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 0b6cca8..d5b5373 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6c93b4e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 4059662a7066ea9d0ec73081fe3298c7d690bf5b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 01:54:45 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 2642242..0b6cca8 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^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 55f2d516ffc7a2d09e8249ba0f941d3c0f224469 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 03:19:20 +0000 Subject: [PATCH 107/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a73fd9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6c93b4e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f18d7a5d4fe0697b30b6f70a189fcfb9c0539b64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 03:19:36 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6160 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 be4180e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-06-01T01:27:33.499Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a73fd9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 0b6cca8..d5b5373 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6c93b4e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 3a83219be95952b5fe02d2ca455f3603f94d4657 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 02:33:27 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 2642242..0b6cca8 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^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 440330956ba81e2e750e279a190beeaaaf5a2715 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 03:53:47 +0000 Subject: [PATCH 110/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a73fd9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6c93b4e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6e5de41f47f85c8cca6c72df529902867c796ded Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 03:54:04 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6197 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 62f508b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-07-01T01:49:35.773Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a73fd9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 0b6cca8..d5b5373 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6c93b4e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 52fd9f91d4650392f2fc6e14e0ee505c5124a430 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 03:10:32 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index bf1bce7..dec4a26 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.1", - "@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 21b9b1ac377299cdb46bebdbd5e03acfe0a03a1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 03:43:06 +0000 Subject: [PATCH 113/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a73fd9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6c93b4e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c0efc15313a94bdc39b134f4d2a194ef63ec6347 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 03:43:27 +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 | 217 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 764 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 47 files changed, 4867 insertions(+), 6375 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 da24c2e..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,764 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 `vind2bind`. -*/ -#include -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9cb4379 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index dec4a26..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.1", - "@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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..631728f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 634349704c5ba6aa7ffa122bf91ea4b7c3cf0a9d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 03:51:54 +0000 Subject: [PATCH 115/140] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e599de..326cfd5 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs'; ``` #### vind2bind( shape, strides, offset, order, idx, mode ) @@ -131,7 +131,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 2b4badefbfad706ca198988b24cbbb205bbdc1f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 03:51:55 +0000 Subject: [PATCH 116/140] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 326cfd5..b502936 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-vind2bind/tags). For example, + ```javascript import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs'; ``` @@ -131,7 +136,7 @@ import shape2strides from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sh import strides2offset from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs'; +import vind2bind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 8d12e794f9f87bde65abcd3aa791b0230d5c3688 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 02:42:03 +0000 Subject: [PATCH 117/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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index a785d1d..42e3f2f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^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 e6675e9b20b6bd0267376ad64011afb9df88e60b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 05:19:31 +0000 Subject: [PATCH 118/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9cb4379..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 631728f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7a6603bf4bfe86759410dec3c79e213239b18137 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 05:19:48 +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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 761 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6326 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 cdc79dc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T01:56:31.894Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 df94eb0..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,761 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9cb4379 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 42e3f2f..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..631728f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 2df99fe3740704dbc8bc40c3b0d13725028e97ec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:21:42 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index a785d1d..42e3f2f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^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 3452440cf155801840e706590aca515eddc04752 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 19:00:00 +0000 Subject: [PATCH 121/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9cb4379..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 631728f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From db3154bebefafefd299be4b6e55215eba3c949e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 19:00:24 +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 | 251 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 761 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6409 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 5a4d325..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T16:48:46.706Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 df94eb0..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,761 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9cb4379 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 42e3f2f..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..631728f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From fa637ddea3f37506b4181e2bcf48b23d4a15829c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 02:46:24 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index ccf9652..babbd08 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^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 9fbd24de738eb5d5832c67a1ad6a8e01840edd1f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 05:07:30 +0000 Subject: [PATCH 124/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9cb4379..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 631728f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7a5d29fb2cf115d7b277da2c245d5ea675fb6ccf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 05:07:46 +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 | 250 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 761 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6408 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 b29af7b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T02:04:49.161Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 df94eb0..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,761 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9cb4379 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index babbd08..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..631728f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 15ac21589d036b7255240312cd365486efe18a1c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 02:50:28 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index ccf9652..babbd08 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^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 45e71202864a25107a8c7f2b9ca3698173f367a0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 05:09:33 +0000 Subject: [PATCH 127/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9cb4379..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 631728f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 69442cd9b1becc825e909349bd9c48379cc76585 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 05:09:46 +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 | 250 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 761 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6408 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 e965061..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T02:11:51.049Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 df94eb0..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,761 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9cb4379 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index babbd08..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..631728f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 07506d7e2801df237a2d37c067df0e4caef9c4e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 02:47:34 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index ccf9652..babbd08 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^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 212947d8be04c0f036cde8fe46afc9b7b1b617aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 04:52:56 +0000 Subject: [PATCH 130/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9cb4379..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 631728f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1e563289c014b728956f8c802258e2f3005e636f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 04:53:07 +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 | 250 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 --- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 761 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6408 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 508252a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T02:10:11.766Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 df94eb0..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,761 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9cb4379 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index babbd08..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..631728f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From a50f701b91a0c8c1daa4e9e432b89b48606ede4d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 02:54:44 +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 4177905..d743ee5 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 // @@ -85,7 +85,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index 8cbd8d6..9325a0a 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^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 bc7f3d5b9af5f09e4e7e8b39e6b93b61f214608f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 05:13:14 +0000 Subject: [PATCH 133/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9cb4379..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 631728f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 123dad3e11ad707ffdd6e22aa020aa0e338ef0a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 05:13:32 +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 | 250 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 761 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 115 - manifest.json | 41 - package.json | 65 +- src/main.c | 113 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 49 files changed, 4867 insertions(+), 6513 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.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 460716c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T02:16:58.628Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 72586b8..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 df94eb0..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,761 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index cbf968e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var i=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var m=i(function(y,v){ -var b=require('@stdlib/error-tools-fmtprodmsg/dist');function g(f,a,s,c,r,l){var u,n,o,t,e;for(u=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(b('0jf5E',n,r));if(o=s,c==="column-major"){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],o+=t*a[e];return o}v.exports=g -});var w=m();module.exports=w; -/** @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 ac930ca..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 a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDC,IAAU,eAAiB,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAX,EAAO,QAAUE,IC1EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9cb4379 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5460344 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d743ee5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order === 'column-major' ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 9325a0a..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^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-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..631728f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 1e632c64bd3e242263bf956842ba23f249e21406 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:53:51 +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 d4b03fb..842cb58 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -86,7 +86,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index af90d70..db4362d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "github:stdlib-js/ndarray-base-assert-is-column-major-string#main", "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^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 80c201c634953332d8f15782048416dfe720f604 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:54:14 +0000 Subject: [PATCH 136/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9cb4379..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(e,o,t,f,n,s){var i,l,m,a,d;for(i=e.length,l=1,d=0;d=l&&(n=l-1);else if("wrap"===s)n<0?(n+=l)<0&&0!==(n%=l)&&(n+=l):n>=l&&(n-=l)>=l&&(n%=l);else if("normalize"===s&&n<0&&(n+=l),n<0||n>=l)throw new RangeError(r("0jf5E",l,n));if(m=t,"column-major"===f){for(d=0;d=0;d--)n-=a=n%e[d],n/=e[d],m+=a*o[d];return m}export{e as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5460344..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format"],"mappings":";;iGAiDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACS,iBAAVC,EAA2B,CAC/B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 631728f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5d2df648f3b84e3cbbcf5a160106fddbd48b7550 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:54:34 +0000 Subject: [PATCH 137/140] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 251 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 761 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 116 - manifest.json | 41 - package.json | 66 +- src/main.c | 113 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 714 --- 48 files changed, 4867 insertions(+), 6518 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e6e9b83..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 df94eb0..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,761 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9b58e4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var s=c(function(j,v){ -var b=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),g=require('@stdlib/error-tools-fmtprodmsg/dist');function q(f,a,i,m,r,l){var o,n,u,t,e;for(o=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(g('0jf5E',n,r));if(u=i,b(m)){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],u+=t*a[e];return u}v.exports=q -});var w=s();module.exports=w; -/** @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 3a44d32..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 isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDL,EAAeM,CAAM,EAAI,CAC7B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAZ,EAAO,QAAUG,IC3EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c8ff4c6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function s(s,t,o,n,i,m){var f,a,l,d,j;for(f=s.length,a=1,j=0;j=a&&(i=a-1);else if("wrap"===m)i<0?(i+=a)<0&&0!==(i%=a)&&(i+=a):i>=a&&(i-=a)>=a&&(i%=a);else if("normalize"===m&&i<0&&(i+=a),i<0||i>=a)throw new RangeError(e("0jf5E",a,i));if(l=o,r(n)){for(j=0;j=0;j--)i-=d=i%s[j],i/=s[j],l+=d*t[j];return l}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7234843 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport isColumnMajor from '@stdlib/ndarray-base-assert-is-column-major-string';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format","isColumnMajor"],"mappings":";;+MAkDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACDY,EAAeX,GAAU,CAC7B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 842cb58..0000000 --- a/lib/main.js +++ /dev/null @@ -1,116 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( isColumnMajor( order ) ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index db4362d..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,42 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-column-major-string": "github:stdlib-js/ndarray-base-assert-is-column-major-string#main", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^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-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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c80a6d4 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4d2c62..0000000 --- a/test/test.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 99edc51ebf6fad1e436b87ad205b54f413adac49 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 09:10:11 +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 d4b03fb..842cb58 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -86,7 +86,7 @@ function vind2bind( shape, strides, offset, order, idx, mode ) { idx += len; } if ( idx < 0 || idx >= len ) { - throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) ); + throw new RangeError( format( '0jf5E', len, idx ) ); } } // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... diff --git a/package.json b/package.json index af90d70..db4362d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "github:stdlib-js/ndarray-base-assert-is-column-major-string#main", "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^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 3ef7797bc7db4e6fa8ab433dd7ebfcbee77e3a9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 09:10:34 +0000 Subject: [PATCH 139/140] Remove files --- index.d.ts | 53 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4900 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index aef0a92..0000000 --- a/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx - linear index in an array view -* @param mode - specifies how to handle a linear index which exceeds array dimensions -* @throws linear index must not exceed array dimensions -* @returns linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -declare function vind2bind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = vind2bind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c8ff4c6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function s(s,t,o,n,i,m){var f,a,l,d,j;for(f=s.length,a=1,j=0;j=a&&(i=a-1);else if("wrap"===m)i<0?(i+=a)<0&&0!==(i%=a)&&(i+=a):i>=a&&(i-=a)>=a&&(i%=a);else if("normalize"===m&&i<0&&(i+=a),i<0||i>=a)throw new RangeError(e("0jf5E",a,i));if(l=o,r(n)){for(j=0;j=0;j--)i-=d=i%s[j],i/=s[j],l+=d*t[j];return l}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7234843..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport isColumnMajor from '@stdlib/ndarray-base-assert-is-column-major-string';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format","isColumnMajor"],"mappings":";;+MAkDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACDY,EAAeX,GAAU,CAC7B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c80a6d4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9272ecef211bfc777846365981fd90e4f2c133c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 09:11:11 +0000 Subject: [PATCH 140/140] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 253 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 554 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 761 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 50 - docs/types/test.ts | 145 - examples/index.js | 56 - include/stdlib/ndarray/base/vind2bind.h | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 46 - lib/main.js | 116 - manifest.json | 41 - package.json | 66 +- src/main.c | 113 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 846 --- 48 files changed, 4867 insertions(+), 6652 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/vind2bind.h rename docs/types/index.d.ts => index.d.ts (95%) create mode 100644 index.mjs create mode 100644 index.mjs.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.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e6e9b83..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/vind2bind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d4a2521..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/vind2bind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdebb7c..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: '23 11 * * 4' - - # 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 + + ```
@@ -207,7 +198,7 @@ for ( i = 0; i < len; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. 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 4eed526..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,554 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var pkg = require( './../package.json' ).name; -var vind2bind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=throw,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len ); - out = vind2bind( shape, strides, offset, order, idx, 'throw' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'wrap' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( 'should 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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'clamp' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - strides[ 1 ] *= -1; - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=row-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'row-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== out ) { - b.fail( '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,order=column-major', function benchmark( b ) { - var strides; - var offset; - var shape; - var order; - var out; - var len; - var idx; - var i; - - shape = [ 10, 10, 10 ]; - order = 'column-major'; - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - len = numel( shape ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = floor( randu()*len*2.0 ) - len; - out = vind2bind( shape, strides, offset, order, idx, 'normalize' ); - if ( out !== 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 df94eb0..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,761 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 -#include -#include -#include -#include -#include -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/vind2bind.h" - -#define NAME "vind2bind" -#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; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_ERROR ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_WRAP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_CLAMP ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, -10, 1 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, -10, 100 }; - int64_t offset = 90; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t idx; - int64_t ind; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 1, 10, 100 }; - int64_t offset = 0; - int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, idx, STDLIB_NDARRAY_INDEX_NORMALIZE ); - if ( ind < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( ind < -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,order=row-major\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,order=column-major\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=error,order=row-major,offset=0\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=error,order=column-major,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=wrap,order=row-major\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=wrap,order=column-major\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,order=row-major,offset=0\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,order=column-major,offset=0\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,order=row-major\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,order=column-major\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=clamp,order=row-major,offset=0\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=clamp,order=column-major,offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=row-major,offset=0\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=normalize,order=column-major,offset=0\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 4bbc59f..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/vind2bind" -%% click B href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[production-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-vind2bind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-vind2bind/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 5b44962..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import vind2bind from '../docs/types/index'; -export = vind2bind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9b58e4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var c=function(f,a){return function(){return a||f((a={exports:{}}).exports,a),a.exports}};var s=c(function(j,v){ -var b=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),g=require('@stdlib/error-tools-fmtprodmsg/dist');function q(f,a,i,m,r,l){var o,n,u,t,e;for(o=f.length,n=1,e=0;e=n&&(r=n-1);else if(l==="wrap")r<0?(r+=n,r<0&&(r%=n,r!==0&&(r+=n))):r>=n&&(r-=n,r>=n&&(r%=n));else if(l==="normalize"&&r<0&&(r+=n),r<0||r>=n)throw new RangeError(g('0jf5E',n,r));if(u=i,b(m)){for(e=0;e=0;e--)t=r%f[e],r-=t,r/=f[e],u+=t*a[e];return u}v.exports=q -});var w=s();module.exports=w; -/** @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 3a44d32..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 isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 linear index in an array view to a linear index in an underlying data buffer.\n*\n* @module @stdlib/ndarray-base-vind2bind\n*\n* @example\n* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\n\n// MODULES //\n\nvar vind2bind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = vind2bind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAM,OACdO,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,CAAE,EAEjB,GAAKL,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYT,EAAQ,gHAAiHS,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAMN,EACDL,EAAeM,CAAM,EAAI,CAC7B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IACvBD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAEA,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAC1BD,EAAIL,EAAMJ,EAAOU,CAAE,EACnBN,GAAOK,EACPL,GAAOJ,EAAOU,CAAE,EAChBF,GAAOC,EAAIR,EAASS,CAAE,EAEvB,OAAOF,CACR,CAKAZ,EAAO,QAAUG,IC3EjB,IAAIY,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "format", "vind2bind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "s", "i", "vind2bind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b770901..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an array view to a linear index in an underlying - data buffer. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - idx: integer - Linear index in an array view. - - mode: string - Specifies how to handle a linear index which exceeds array dimensions. - If equal to 'throw', the function throws an error when a linear index - exceeds array dimensions. If equal to 'normalize', the function - normalizes negative linear indices and throws an error when a linear - index exceeds array dimensions. If equal to 'wrap', the function wraps - around a linear index exceeding array dimensions using modulo - arithmetic. If equal to 'clamp', the function sets a linear index - exceeding array dimensions to either `0` (minimum linear index) or the - maximum linear index. Default: 'throw'. - - Returns - ------- - idx: integer - Linear index in an underlying data buffer. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 1, 'throw' ) - 7 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 5d37df2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import vind2bind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, 1, 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 = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( true, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( false, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( null, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( undefined, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( '5', strides, offset, order, 1, mode ); // $ExpectError - vind2bind( [ '1', '2' ], strides, offset, order, 1, mode ); // $ExpectError - vind2bind( {}, strides, offset, order, 1, mode ); // $ExpectError - vind2bind( ( x: number ): number => x, strides, offset, order, 1, 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 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, true, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, false, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, null, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, undefined, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, '5', offset, order, 1, mode ); // $ExpectError - vind2bind( shape, [ '1', '2' ], offset, order, 1, mode ); // $ExpectError - vind2bind( shape, {}, offset, order, 1, mode ); // $ExpectError - vind2bind( shape, ( x: number ): number => x, offset, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, true, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, false, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, null, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, undefined, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, '5', order, 1, mode ); // $ExpectError - vind2bind( shape, strides, [ '1', '2' ], order, 1, mode ); // $ExpectError - vind2bind( shape, strides, {}, order, 1, mode ); // $ExpectError - vind2bind( shape, strides, ( x: number ): number => x, order, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a recognized array order... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const mode = 'throw'; - vind2bind( shape, strides, offset, 'abc', 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, true, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, false, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, null, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, undefined, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, 123, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, [], 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, {}, 1, mode ); // $ExpectError - vind2bind( shape, strides, offset, ( x: number ): number => x, 1, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - const mode = 'throw'; - vind2bind( shape, strides, offset, order, true, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, false, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, null, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, undefined, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, 'abc', mode ); // $ExpectError - vind2bind( shape, strides, offset, order, [], mode ); // $ExpectError - vind2bind( shape, strides, offset, order, {}, mode ); // $ExpectError - vind2bind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a recognized mode... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind( shape, strides, offset, order, 1, 123 ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, true ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, false ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, null ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, undefined ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, 'abc' ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, [] ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, {} ); // $ExpectError - vind2bind( shape, strides, offset, order, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3 ]; - const strides = [ -3, 1 ]; - const offset = 6; - const order = 'row-major'; - vind2bind(); // $ExpectError - vind2bind( shape ); // $ExpectError - vind2bind( shape, strides ); // $ExpectError - vind2bind( shape, strides, offset ); // $ExpectError - vind2bind( shape, strides, offset, order ); // $ExpectError - vind2bind( shape, strides, offset, order, 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 49167b4..0000000 --- a/examples/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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 vind2bind = require( './../lib' ); - -// Specify array meta data: -var shape = [ 3, 3, 3 ]; -var order = 'row-major'; - -// Compute array meta data: -var len = numel( shape ); -var strides = shape2strides( shape, order ); - -// Randomly flip the sign of strides... -var i; -for ( i = 0; i < shape.length; i++ ) { - if ( randu() < 0.5 ) { - strides[ i ] *= -1; - } -} - -// Compute the underlying data buffer index offset: -var offset = strides2offset( shape, strides ); - -// Print array info: -console.log( 'Dims: %s', shape.join( 'x' ) ); -console.log( 'Strides: %s', strides.join( ',' ) ); -console.log( 'Offset: %d', offset ); - -// For each view index, determine the corresponding index into an array's underlying data buffer... -var ind; -for ( i = 0; i < len; i++ ) { - ind = vind2bind( shape, strides, offset, order, i, 'throw' ); - console.log( 'view[%d] => buffer[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/vind2bind.h b/include/stdlib/ndarray/base/vind2bind.h deleted file mode 100644 index ef09218..0000000 --- a/include/stdlib/ndarray/base/vind2bind.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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_VIND2BIND_H -#define STDLIB_NDARRAY_BASE_VIND2BIND_H - -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.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 a linear index in an array view to a linear index in an underlying data buffer. -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_VIND2BIND_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index e7b5423..aef0a92 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { Mode, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c8ff4c6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function s(s,t,o,n,i,m){var f,a,l,d,j;for(f=s.length,a=1,j=0;j=a&&(i=a-1);else if("wrap"===m)i<0?(i+=a)<0&&0!==(i%=a)&&(i+=a):i>=a&&(i-=a)>=a&&(i%=a);else if("normalize"===m&&i<0&&(i+=a),i<0||i>=a)throw new RangeError(e("0jf5E",a,i));if(l=o,r(n)){for(j=0;j=0;j--)i-=d=i%s[j],i/=s[j],l+=d*t[j];return l}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7234843 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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\nimport isColumnMajor from '@stdlib/ndarray-base-assert-is-column-major-string';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an array view to a linear index in an underlying data buffer.\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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an array view\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an underlying data buffer\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = vind2bind( shape, strides, offset, order, 1, mode );\n* // returns 7\n*/\nfunction vind2bind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( '0jf5E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tind = offset;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default vind2bind;\n"],"names":["vind2bind","shape","strides","offset","order","idx","mode","ndims","len","ind","s","i","length","RangeError","format","isColumnMajor"],"mappings":";;+MAkDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAJ,EAAQN,EAAMW,OACdJ,EAAM,EACAG,EAAI,EAAGA,EAAIJ,EAAOI,IACvBH,GAAOP,EAAOU,GAEf,GAAc,UAATL,EACCD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,QAEP,GAAc,SAATF,EACND,EAAM,GACVA,GAAOG,GACI,GAEG,KADbH,GAAOG,KAENH,GAAOG,GAGEH,GAAOG,IAClBH,GAAOG,IACKA,IACXH,GAAOG,QAOT,GAHc,cAATF,GAAwBD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAIK,WAAYC,EAAQ,QAASN,EAAKH,IAK9C,GADAI,EAAMN,EACDY,EAAeX,GAAU,CAC7B,IAAMO,EAAI,EAAGA,EAAIJ,EAAOI,IAEvBN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACP,CAED,IAAME,EAAIJ,EAAM,EAAGI,GAAK,EAAGA,IAE1BN,GADAK,EAAIL,EAAMJ,EAAOU,GAEjBN,GAAOJ,EAAOU,GACdF,GAAOC,EAAIR,EAASS,GAErB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1dbc7f3..0000000 --- a/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 a linear index in an array view to a linear index in an underlying data buffer. -* -* @module @stdlib/ndarray-base-vind2bind -* -* @example -* var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ - -// MODULES // - -var vind2bind = require( './main.js' ); - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 842cb58..0000000 --- a/lib/main.js +++ /dev/null @@ -1,116 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* @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 {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param {integer} idx - linear index in an array view -* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions -* @throws {RangeError} linear index must not exceed array dimensions -* @returns {NonNegativeInteger} linear index in an underlying data buffer -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = vind2bind( shape, strides, offset, order, 1, mode ); -* // returns 7 -*/ -function vind2bind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var s; - var i; - - ndims = shape.length; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode === 'clamp' ) { - if ( idx < 0 ) { - idx = 0; - } else if ( idx >= len ) { - idx = len - 1; - } - } else if ( mode === 'wrap' ) { - if ( idx < 0 ) { - idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len - if ( idx < 0 ) { - idx %= len; - if ( idx !== 0 ) { - idx += len; - } - } - } else if ( idx >= len ) { - idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len - if ( idx >= len ) { - idx %= len; - } - } - } else { - if ( mode === 'normalize' && idx < 0 ) { - idx += len; - } - if ( idx < 0 || idx >= len ) { - throw new RangeError( format( '0jf5E', len, idx ) ); - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( isColumnMajor( order ) ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} - - -// EXPORTS // - -module.exports = vind2bind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 5807c25..0000000 --- a/manifest.json +++ /dev/null @@ -1,41 +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", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index db4362d..c59fb19 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an array view to a linear index in an underlying data buffer.", "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" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,42 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-column-major-string": "github:stdlib-js/ndarray-base-assert-is-column-major-string#main", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^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-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 186a4e9..0000000 --- a/src/main.c +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/vind2bind.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include - -/** -* Converts a linear index in an array view to a linear index in an underlying data buffer. -* -* ## Notes -* -* - In "error" and "normalize" modes, the function returns `-1` if an index 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 order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param idx linear index in an array view -* @param mode specifies how to handle a linear index which exceeds array dimensions -* @return index -* -* @example -* #include "stdlib/ndarray/base/vind2bind.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_vind2bind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 1, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 7 -*/ -int64_t stdlib_ndarray_vind2bind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) { - int64_t index; - int64_t len; - int64_t ind; - int64_t s; - int64_t i; - - index = idx; - len = 1; - for ( i = 0; i < ndims; i++ ) { - len *= shape[ i ]; - } - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( index < 0 ) { - index = 0; - } else if ( index >= len ) { - index = len - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( index < 0 ) { - index += len; // slight optimization to avoid modulo arithmetic when |index| <= len - if ( index < 0 ) { - index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C - if ( index != 0 ) { - index += len; - } - } - } else if ( index >= len ) { - index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len - if ( index >= len ) { - index %= len; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) { - index += len; - } - if ( index < 0 || index >= len ) { - return -1; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - ind = offset; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = index % shape[ i ]; // assume nonnegative "shape" - index -= s; - index /= shape[ i ]; - ind += s * strides[ i ]; - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c80a6d4 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8b8da96..0000000 --- a/test/test.js +++ /dev/null @@ -1,846 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var vind2bind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof vind2bind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major, transposed)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major, transposed)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major, permuted)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2, 2 ]; - order = 'row-major'; - strides = [ 1, 4, 2 ]; // normal: [ 4, 2, 1 ] - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 4, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 6, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 6, 'throw' ); - t.strictEqual( idx, 5, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 7, 'throw' ); - t.strictEqual( idx, 7, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major, permuted)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2, 2 ]; - order = 'column-major'; - strides = [ 2, 4, 1 ]; // normal: [ 1, 2, 4 ] - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 4, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 6, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 6, 'throw' ); - t.strictEqual( idx, 5, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 7, 'throw' ); - t.strictEqual( idx, 7, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'throw' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - vind2bind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - vind2bind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `wrap`, the function wraps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps a linear index which exceeds array dimensions (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - idx = vind2bind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=row-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (offset=0,order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - // Iteration order => [ 0, 1, 2, 3 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative linear indices (order=column-major)', function test( t ) { - var strides; - var offset; - var order; - var shape; - var idx; - - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - // Iteration order => [ 2, 3, 0, 1 ] - - idx = vind2bind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = vind2bind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -});