From bf17954545249da627e5ede91ddf2a96aa6954ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 07:10:55 +0000 Subject: [PATCH 001/182] Auto-generated commit 631e03ee80017e3f92b94b26db3abb752f4caa54 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 250 +++++ index.d.ts | 54 + index.mjs | 4 + index.mjs.map | 1 + package.json | 41 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3549 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..c4b7b50 --- /dev/null +++ b/README.md @@ -0,0 +1,250 @@ + + +# bind2vind + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Convert a linear index in an underlying data buffer to a linear index in an array view. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +``` + +#### bind2vind( shape, strides, offset, order, idx, mode ) + +Converts a linear index in an underlying data buffer to a linear index in an array view. + +```javascript +var shape = [ 3, 3 ]; +var order = 'row-major'; +var strides = [ -3, 1 ]; +var offset = 6; + +var idx = bind2vind( shape, strides, offset, order, 7, 'throw' ); +// returns 1 +``` + +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 = bind2vind( shape, strides, offset, order, -2, 'wrap' ); +// returns 0 + +idx = bind2vind( 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 = bind2vind( 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..2f785c4 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,54 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 underlying data buffer to a linear index in an array view. +* +* @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 underlying data buffer +* @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 array view +* +* @example +* var shape = [ 3, 3 ]; +* var strides = [ -3, 1 ]; +* var offset = 6; +* var order = 'row-major'; +* var mode = 'throw'; +* +* var ind = bind2vind( shape, strides, offset, order, 7, mode ); +* // returns 1 +*/ +declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length + + +// EXPORTS // + +export = bind2vind; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b7a189e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";var t=e,n=r,i=s;var a=function(e,r,s,a,m,o){var d,l,f,p,u,c;for(d=e.length,l=1,c=0;c=l&&(m=l-1);else if("wrap"===o)m<0?(m+=l)<0&&0!==(m%=l)&&(m+=l):m>=l&&(m-=l)>=l&&(m%=l);else if(m<0||m>=l)throw new RangeError(t("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",l,m));if(f=0,"column-major"===a){for(c=d-1;c>=0;c--)(u=r[c])<0?(m-=(p=n(m/u))*u,p+=e[c]-1):m-=(p=n(m/u))*u,f+=p*i(u);return f}for(c=0;c= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"],"names":["format","require$$0","trunc","require$$1","abs","require$$2","lib","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError"],"mappings":";;qQAsBA,IAAIA,EAASC,EACTC,EAAQC,EACRC,EAAMC,EAoGV,IC/EAC,EDMA,SAAoBC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYpB,EAAQ,gHAAiHc,EAAKH,IAIrJ,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAId,EAAOS,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAId,EAAOS,EAAIM,IACJA,EAEZF,GAAOC,EAAIZ,EAAKa,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAId,EAAOS,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAId,EAAOS,EAAIM,IACJA,EAEZF,GAAOC,EAAIZ,EAAKa,GAEjB,OAAOF"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..87a92a6 --- /dev/null +++ b/package.json @@ -0,0 +1,41 @@ +{ + "name": "@stdlib/ndarray-base-bind2vind", + "version": "0.0.0", + "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/ndarray-base-bind2vind.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..45ad90e --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From a7b02ab14dd710d70d655e5b37db32d7400865b3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 23:13:53 +0000 Subject: [PATCH 002/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 e47c69c15f112c2d6a6bc95f7bfd29ea54c90578 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:35:30 +0000 Subject: [PATCH 003/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b7a189e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";var t=e,n=r,i=s;var a=function(e,r,s,a,m,o){var d,l,f,p,u,c;for(d=e.length,l=1,c=0;c=l&&(m=l-1);else if("wrap"===o)m<0?(m+=l)<0&&0!==(m%=l)&&(m+=l):m>=l&&(m-=l)>=l&&(m%=l);else if(m<0||m>=l)throw new RangeError(t("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",l,m));if(f=0,"column-major"===a){for(c=d-1;c>=0;c--)(u=r[c])<0?(m-=(p=n(m/u))*u,p+=e[c]-1):m-=(p=n(m/u))*u,f+=p*i(u);return f}for(c=0;c= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"],"names":["format","require$$0","trunc","require$$1","abs","require$$2","lib","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError"],"mappings":";;qQAsBA,IAAIA,EAASC,EACTC,EAAQC,EACRC,EAAMC,EAoGV,IC/EAC,EDMA,SAAoBC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYpB,EAAQ,gHAAiHc,EAAKH,IAIrJ,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAId,EAAOS,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAId,EAAOS,EAAIM,IACJA,EAEZF,GAAOC,EAAIZ,EAAKa,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAId,EAAOS,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAId,EAAOS,EAAIM,IACJA,EAEZF,GAAOC,EAAIZ,EAAKa,GAEjB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 45ad90e..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From aa5a3cf47d7333a35e74816a8c4991209c9fa19a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:36:21 +0000 Subject: [PATCH 004/182] 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 | 150 -- examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5366 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/bind2vind.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 11d86dd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:21:13.794Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2fd12be..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..23bb8e8 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;8QAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f355f6c --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From fe90c6bd78b4ec8116b1db0a8c0ffa3c77353718 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:48:11 +0000 Subject: [PATCH 005/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 58064643b39878c76f9570264be518ff2af73ae8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 04:03:31 +0000 Subject: [PATCH 006/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 23bb8e8..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;8QAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f355f6c..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 92cdc1187eefcaa2d6919342536660829f676949 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 04:04:21 +0000 Subject: [PATCH 007/182] 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 | 150 -- examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5366 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/bind2vind.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 8bf8889..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:20:38.335Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2fd12be..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..23bb8e8 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;8QAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5535442 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From c72972eff36de50df03682ddae12f1be5812e905 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:40:18 +0000 Subject: [PATCH 008/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 c6830de12eafe5336e37a6c23a1966fa252ab844 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:54:28 +0000 Subject: [PATCH 009/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 23bb8e8..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;8QAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5535442..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 33a75dda365041c08ed6ec58b478609c4ba38454 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:55:16 +0000 Subject: [PATCH 010/182] 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 | 150 -- examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 41 files changed, 2714 insertions(+), 5331 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/bind2vind.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 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2fd12be..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..23bb8e8 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;8QAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1ff39e7 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 557b9d91a595ac4100ddbce49e52decfe5e0fd9d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:54:38 +0000 Subject: [PATCH 011/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 c36a752ff42cdc7c0f4af290e95ac261f6c9e41f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:33:55 +0000 Subject: [PATCH 012/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 23bb8e8..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;8QAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1ff39e7..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 95cf5c4ffc34d0e00b2f5c6e5fa6870548e0dc48 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:34:46 +0000 Subject: [PATCH 013/182] 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 | 150 -- examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5405 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/bind2vind.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 11a384a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:23:52.250Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2fd12be..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b273c78 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..78d5e27 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 91d70bccf4ec5e1e89cbd0015aca2a4ad435355f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:41:40 +0000 Subject: [PATCH 014/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 cf15e1c965fb8f5e93f74f3c3f9f90389da796b3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 17:06:35 +0000 Subject: [PATCH 015/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b273c78..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 78d5e27..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2ee68bdb172861161f9652104b967bce92debcfb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 17:07:31 +0000 Subject: [PATCH 016/182] 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 | 150 -- examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5421 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/bind2vind.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 e08306e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:22:13.572Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2fd12be..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The function does not compile if provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError -} - -// The function does not compile if provided a sixth argument which is not a known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b273c78 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f33885a --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From b41fdce24b6b27ee4d177a18d72a99e45f5590be Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 27 Sep 2022 22:50:11 +0000 Subject: [PATCH 017/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 22c5c7538a8e284111e6057f542ce59f7764dc16 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Sep 2022 00:09:23 +0000 Subject: [PATCH 018/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b273c78..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f33885a..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ce6f1aeb961618a055d891d4ac51d03c8c6f5fbf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Sep 2022 00:10:17 +0000 Subject: [PATCH 019/182] Auto-generated commit --- .editorconfig | 181 -- .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 | 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 | 150 -- examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 41 files changed, 2714 insertions(+), 5420 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/bind2vind.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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b273c78 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d9d6f19 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From b2a065fe3830e5fb902e63a6416ccabba5dd4e50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 05:02:47 +0000 Subject: [PATCH 020/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 4051425d7e0dd520157bd5cf19b9e62229e25536 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 22:27:13 +0000 Subject: [PATCH 021/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b273c78..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d9d6f19..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 7e36ad65388666f347d28e04f03fe9a7aa2fee3b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 22:27:59 +0000 Subject: [PATCH 022/182] 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 | 150 -- examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 2689 +++++++++++++++++++++ test/test.js | 577 ----- 42 files changed, 2714 insertions(+), 5421 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/bind2vind.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 0f21a84..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:48:45.621Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b273c78 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..558b2f3 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 2ddc89f8615b8285b53b41dda463cf76f1c19c43 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 04:33:45 +0000 Subject: [PATCH 023/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 37ad62e4ec1e3d33694949d989cf111ac623fff5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 13:08:48 +0000 Subject: [PATCH 024/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b273c78..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,EAGR,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 558b2f3..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 0885366ce0897b2ead6f7a71e882152003738408 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 13:09:48 +0000 Subject: [PATCH 025/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 4044 +++++++++++++++++++++ test/test.js | 577 --- 42 files changed, 4069 insertions(+), 5421 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/bind2vind.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 05c9657..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:35:19.649Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b273c78 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..67df927 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From a1803a646d789d3acb2c37cdee3dd696e402664b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:20:42 +0000 Subject: [PATCH 026/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f6a1aa6..8da4ff0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 6c4945e808fc34c3742ecdbaac8635448f4b935a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 13:51:02 +0000 Subject: [PATCH 027/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4103 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b273c78..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 67df927..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1307e102ad687e8fbb2f2f450b1b20edcd1757f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 13:51:54 +0000 Subject: [PATCH 028/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 4044 +++++++++++++++++++++ test/test.js | 577 --- 42 files changed, 4069 insertions(+), 5442 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/bind2vind.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 9252f8b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:20:06.336Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b273c78 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8da4ff0..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f3cd666 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 94b9c638aef4e72778bacfda07cc350a5ed9b575 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 02:10:22 +0000 Subject: [PATCH 029/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index d81ced0..1f43aa3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 5cef3321e51d0d2f7294864d7939eb95ade4d89a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 14:57:02 +0000 Subject: [PATCH 030/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4103 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b273c78..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f3cd666..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From aa5f659bc5b0b62e3ac3b8e433d397c39cc813ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 14:57:46 +0000 Subject: [PATCH 031/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 4044 +++++++++++++++++++++ test/test.js | 577 --- 42 files changed, 4069 insertions(+), 5447 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/bind2vind.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 723ea77..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:09:45.763Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b273c78 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 1f43aa3..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a2bf408 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 23041eb6c4d212865bd7b572d0205be1b87d8bb7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 03:31:53 +0000 Subject: [PATCH 032/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index e053328..361c848 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 7629cd86e200ba08db69a56b4b76f2569621c565 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 08:39:39 +0000 Subject: [PATCH 033/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4103 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b273c78..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a2bf408..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f5d359b834c865ad72a42dd109a8a0ef549e9f44 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 08:40:25 +0000 Subject: [PATCH 034/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 4044 +++++++++++++++++++++ test/test.js | 577 --- 42 files changed, 4069 insertions(+), 5458 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/bind2vind.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 5b1dc2f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:26:58.151Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..56d97e6 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 361c848..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e6aa75c --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 06d01a43459121097203c024af5e0f1a9b23b690 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:58:58 +0000 Subject: [PATCH 035/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index e053328..361c848 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.x", "@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 dd4877dfe96cf07a45662eae77ca39bd3ca94903 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 12:28:50 +0000 Subject: [PATCH 036/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4103 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 56d97e6..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e6aa75c..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ca08ef41457ee628dc4ca36046bfe29c6c2cffa1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 12:29:48 +0000 Subject: [PATCH 037/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5458 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/bind2vind.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 560a25c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T01:56:30.160Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 0394fab..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/bind2vind" -click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9b6be76 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;8QAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 361c848..c1bee52 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-trunc": "^0.0.x", - "@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", @@ -95,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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2492498 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 9f9d891c29533f66c7e003d0674cb813910f8022 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 07:53:40 +0000 Subject: [PATCH 038/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index d908099..d79532d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.8", "@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 8ebecb5c30b3346db68d9bb7e4fffff153f52a4f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 17:22:01 +0000 Subject: [PATCH 039/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9b6be76..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;8QAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2492498..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c0ea958d33dd96e15bb08a77643cbed20773a2f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 17:22:48 +0000 Subject: [PATCH 040/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5593 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/bind2vind.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 9fd933a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T05:09:07.149Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..56d97e6 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 d79532d..496748c 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-trunc": "^0.0.8", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ce26ad5 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 289dd941eae5755e1a9253fccd3634b941d6ea9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 08:32:20 +0000 Subject: [PATCH 041/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index d908099..d79532d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.8", "@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 b5a107c435855f3d2de02b4d487e24cdc39a94ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 16:23:46 +0000 Subject: [PATCH 042/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 56d97e6..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ce26ad5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 877820c8f57560f1b187de44871a8c8a08669ea0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 16:24:44 +0000 Subject: [PATCH 043/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5599 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 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/bind2vind.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 e6d7283..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T05:56:53.997Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..56d97e6 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 d79532d..496748c 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-trunc": "^0.0.8", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..37cf76e --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 2017f7e4cc87b3013da1e8f222129989e9722501 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 08:09:57 +0000 Subject: [PATCH 044/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index d908099..d79532d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.8", "@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 21cd25f368bd98015d48e32a1301510b249fef7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 16:04:58 +0000 Subject: [PATCH 045/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 56d97e6..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 37cf76e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From faae8b340af532930489de162518baa3b6634185 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 16:06:00 +0000 Subject: [PATCH 046/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5599 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 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/bind2vind.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 9f4d7af..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T05:34:53.034Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..56d97e6 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 d79532d..496748c 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-trunc": "^0.0.8", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..70093ea --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From e4ba8c9339abef103ccbb95a7b8bf3c8ec7d794c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 07:55:48 +0000 Subject: [PATCH 047/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index d908099..d79532d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.8", "@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 d78ec89ab3e6cdf0761002a37e56c8852b7359c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 16:16:17 +0000 Subject: [PATCH 048/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 56d97e6..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 70093ea..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 115abc945272b95a7aa1b6f2e5b9932cfc18e20d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 16:17:16 +0000 Subject: [PATCH 049/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5599 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 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/bind2vind.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 b748798..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T05:07:02.738Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..56d97e6 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 d79532d..496748c 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-trunc": "^0.0.8", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4170913 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From b24f27e8201a1efd7ee0f9c833c78ddfda951f75 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 07:43:42 +0000 Subject: [PATCH 050/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index d908099..d79532d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.8", "@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 535c2872964647184d99f95ce493aaa0abca6824 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 16:39:22 +0000 Subject: [PATCH 051/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 56d97e6..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4170913..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 48746fef00965b874721bfb1a9e493484d08bbe7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 16:40:10 +0000 Subject: [PATCH 052/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5599 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 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/bind2vind.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 8760f3c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T05:03:45.507Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..56d97e6 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 d79532d..496748c 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-trunc": "^0.0.8", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c70b80b --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 164efb6482fb8656effea6544b4adc0f7647c807 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 08:38:32 +0000 Subject: [PATCH 053/182] 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 d0a03c8..22bf80a 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0Lw5S', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index d908099..d79532d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.0.8", "@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 928411986f54c64717668fa3102afb718e1ff391 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 17:20:31 +0000 Subject: [PATCH 054/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 56d97e6..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c70b80b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2f58dcc4379a052746e87b6c7af9b2967af094d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 17:21:22 +0000 Subject: [PATCH 055/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 42 files changed, 6202 insertions(+), 5599 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 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/bind2vind.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 5269b13..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T05:41:41.399Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 fa7cf04..2f785c4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..56d97e6 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22bf80a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0Lw5S', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 d79532d..496748c 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.0.6", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-trunc": "^0.0.8", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b9c021e --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From d90b75010496d8f7f4d897e1f9fb80b7c059798a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 00:23:31 +0000 Subject: [PATCH 056/182] 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 d0a03c8..126ffba 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0i35E,L1', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index 7e11cd4..3378c51 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.1.0", "@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 a3c425ba79c3a0f3200b00cf0b1643204d7f659b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 01:44:56 +0000 Subject: [PATCH 057/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 2f785c4..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 56d97e6..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0Lw5S",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0Lw5S', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;qRAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAI7C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b9c021e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 15e77d7a86e512314e6d95fb18d5ac94e41933ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 01:46:50 +0000 Subject: [PATCH 058/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/test.js | 577 -- 45 files changed, 6202 insertions(+), 5633 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/bind2vind.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 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6beab4c..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2c06540..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 72a658c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),l=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var o,a,s,f,e,n;for(o=u.length,a=1,n=0;n=a&&(r=a-1);else if(v==="wrap")r<0?(r+=a,r<0&&(r%=a,r!==0&&(r+=a))):r>=a&&(r-=a,r>=a&&(r%=a));else if(r<0||r>=a)throw new RangeError(g('0i35E',a,r));if(s=0,b==="column-major"){for(n=o-1;n>=0;n--)e=t[n],e<0?(f=l(r/e),r-=f*e,f+=u[n]-1):(f=l(r/e),r-=f*e),s+=f*m(e);return s}for(n=0;n= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICpFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 8f5da7f..e0a78e3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5ea8747 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;4RAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAIhD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 126ffba..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E,L1', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 3378c51..174ed6a 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.1.0", - "@stdlib/math-base-special-trunc": "^0.1.0", - "@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.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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f712db1 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From a1fc698bf01838f96d858e2fb1ce2cd36c502c77 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 01:59:19 +0000 Subject: [PATCH 059/182] 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 78ede37..a9e6533 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.1.0-esm/index.mjs'; ``` #### bind2vind( 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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.1.0-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 2fc2930ce8ec8336b612b1ba71bff5d55854fb97 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 01:59:20 +0000 Subject: [PATCH 060/182] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9e6533..1b75ad6 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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-bind2vind/tags). For example, + ```javascript import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.1.0-esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 3d502fdc2b0b4fdd00fcf3872b1a26ea51ccaf9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 11:12:00 +0000 Subject: [PATCH 061/182] 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 d0a03c8..126ffba 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0i35E,L1', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index fe6b69c..6bef9b4 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.1.0", "@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 a38617953612e9729aec5a0ed2153d837925285c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 17:52:01 +0000 Subject: [PATCH 062/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 e0a78e3..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5ea8747..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;4RAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAIhD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f712db1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9444d28ab362b23fa42e23df19765084906945e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 17:55:22 +0000 Subject: [PATCH 063/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 577 -- test/test.js | 577 -- 47 files changed, 6202 insertions(+), 6269 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/bind2vind.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 8516c3a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T03:35:41.697Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 a475709..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 72a658c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),l=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var o,a,s,f,e,n;for(o=u.length,a=1,n=0;n=a&&(r=a-1);else if(v==="wrap")r<0?(r+=a,r<0&&(r%=a,r!==0&&(r+=a))):r>=a&&(r-=a,r>=a&&(r%=a));else if(r<0||r>=a)throw new RangeError(g('0i35E',a,r));if(s=0,b==="column-major"){for(n=o-1;n>=0;n--)e=t[n],e<0?(f=l(r/e),r-=f*e,f+=u[n]-1):(f=l(r/e),r-=f*e),s+=f*m(e);return s}for(n=0;n= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICpFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 8f5da7f..e0a78e3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..25dff7e --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.0-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAIhD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 126ffba..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E,L1', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 6bef9b4..174ed6a 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.1.0", - "@stdlib/math-base-special-trunc": "^0.1.0", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d5cc7d6 --- /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 3e43df4..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 bind2vind = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From d7021b8d2be2d39b7db4691e549397fc8155d488 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 15:02:14 +0000 Subject: [PATCH 064/182] 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 d0a03c8..126ffba 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0i35E,L1', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index f170565..b5fd582 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.1.0", "@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 3025c22df31b4b2c03d936800376981c81ef9d2e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 18:54:05 +0000 Subject: [PATCH 065/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 e0a78e3..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 25dff7e..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.0-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAIhD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d5cc7d6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e9cbb00687bfa1e8119e2e210676abb1db36d2ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 18:57:17 +0000 Subject: [PATCH 066/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 577 -- test/test.js | 577 -- 46 files changed, 6202 insertions(+), 6268 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/bind2vind.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 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 a475709..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 72a658c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),l=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var o,a,s,f,e,n;for(o=u.length,a=1,n=0;n=a&&(r=a-1);else if(v==="wrap")r<0?(r+=a,r<0&&(r%=a,r!==0&&(r+=a))):r>=a&&(r-=a,r>=a&&(r%=a));else if(r<0||r>=a)throw new RangeError(g('0i35E',a,r));if(s=0,b==="column-major"){for(n=o-1;n>=0;n--)e=t[n],e<0?(f=l(r/e),r-=f*e,f+=u[n]-1):(f=l(r/e),r-=f*e),s+=f*m(e);return s}for(n=0;n= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICpFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 8f5da7f..e0a78e3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..148fb1b --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.0-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAIhD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 126ffba..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E,L1', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 b5fd582..174ed6a 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.1.0", - "@stdlib/math-base-special-trunc": "^0.1.0", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5a88647 --- /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 3e43df4..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 bind2vind = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From 7fbea248a465ce8d4b87e6f238732ab759eec5c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 11:40:16 +0000 Subject: [PATCH 067/182] 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 d0a03c8..126ffba 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -84,7 +84,7 @@ function bind2vind( 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( '0i35E,L1', len, idx ) ); } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... ind = 0; diff --git a/package.json b/package.json index ea57282..8069af6 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.1.1", "@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 d358e1a2a9dd1d99ce5df3a97a98265e150835c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 18:09:18 +0000 Subject: [PATCH 068/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 e0a78e3..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 148fb1b..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.0-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAIhD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5a88647..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a1e0356e778c344a2aeb7af9435ad17df2d05a4a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 18:11:27 +0000 Subject: [PATCH 069/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 125 - manifest.json | 41 - package.json | 66 +- src/main.c | 120 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 577 -- 47 files changed, 6202 insertions(+), 5733 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/bind2vind.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 d0a3cfc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T03:46:42.046Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 a475709..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 8d8eccf..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 ec1106d..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 72a658c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),l=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var o,a,s,f,e,n;for(o=u.length,a=1,n=0;n=a&&(r=a-1);else if(v==="wrap")r<0?(r+=a,r<0&&(r%=a,r!==0&&(r+=a))):r>=a&&(r-=a,r>=a&&(r%=a));else if(r<0||r>=a)throw new RangeError(g('0i35E',a,r));if(s=0,b==="column-major"){for(n=o-1;n>=0;n--)e=t[n],e<0?(f=l(r/e),r-=f*e,f+=u[n]-1):(f=l(r/e),r-=f*e),s+=f*m(e);return s}for(n=0;n= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAI3J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICpFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 45d6729..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index 5d0de57..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 8f5da7f..e0a78e3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..49ce50f --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAIhD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 126ffba..0000000 --- a/lib/main.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E,L1', len, idx ) ); - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 8069af6..174ed6a 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-trunc": "^0.1.1", - "@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", @@ -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 76ea92f..0000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = idx / s; // truncates - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = idx / s; // cppcheck-suppress zerodivcond // truncates - idx -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2d85ca5 --- /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 ec4f7a7..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 bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); From adbfa73b5d342c091f0c9da86dd58ff77dff713d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:27:43 +0000 Subject: [PATCH 070/182] 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 785cc42..1f00c67 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E,L1', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 31a2d67..917a954 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.1.1", "@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 9be3a123abbb129eef60c84c7b142e368c1f15e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:31:40 +0000 Subject: [PATCH 071/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 e0a78e3..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 49ce50f..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if(n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAIhD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2d85ca5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 920f670bd94cfdf97e05be82aac0f871362da224 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:34:14 +0000 Subject: [PATCH 072/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 66 +- src/main.c | 127 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 46 files changed, 6202 insertions(+), 6397 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/bind2vind.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 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 a475709..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 ecce344..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ef34851 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAKjD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 1f00c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E,L1', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 917a954..174ed6a 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-trunc": "^0.1.1", - "@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", @@ -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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cbc5a20 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 8ba937adc1f4f9e6234d49b846701f4ce506d303 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 09:00:22 +0000 Subject: [PATCH 073/182] 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 785cc42..1f00c67 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E,L1', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 31a2d67..917a954 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.1.1", "@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 0090a5b5a18ee434296e5cbbd19e5e34e20b651f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 05:08:03 +0000 Subject: [PATCH 074/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ef34851..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAKjD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cbc5a20..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8c56737c459a8f6ca5d6abe44805f286fa0fb7db Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 05:10:41 +0000 Subject: [PATCH 075/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 66 +- src/main.c | 127 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 47 files changed, 6202 insertions(+), 6398 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/bind2vind.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 feb5089..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T03:57:01.136Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 a475709..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 ecce344..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ef34851 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAKjD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 1f00c67..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E,L1', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 917a954..174ed6a 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-trunc": "^0.1.1", - "@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", @@ -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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f89a0ca --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From e5f9f3c57c4dae3ceb556e2c6246878df9918a52 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:35:52 +0000 Subject: [PATCH 076/182] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 74611b9..2cf48d2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.1.1", "@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 0f2ea7aa5d740688bf12e7ecd59fe34af311b402 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 12:06:22 +0000 Subject: [PATCH 077/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ef34851..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E,L1",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E,L1', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,WAAYP,EAAKH,IAKjD,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f89a0ca..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a2ceff52f4131e4384883319c590d3ed5b529a39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 12:06:46 +0000 Subject: [PATCH 078/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 66 +- src/main.c | 127 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 6202 insertions(+), 6404 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/bind2vind.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 2889e19..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T03:26:18.910Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 aa0ab13..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 3931316..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6d658e3 --- /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";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,n,i,a,m,o){var d,l,f,p,u,c;for(d=t.length,l=1,c=0;c=l&&(m=l-1);else if("wrap"===o)m<0?(m+=l)<0&&0!==(m%=l)&&(m+=l):m>=l&&(m-=l)>=l&&(m%=l);else if("normalize"===o&&m<0&&(m+=l),m<0||m>=l)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",l,m));if(f=0,"column-major"===a){for(c=d-1;c>=0;c--)(u=n[c])<0?(m-=(p=r(m/u))*u,p+=t[c]-1):m-=(p=r(m/u))*u,f+=p*s(u);return f}for(c=0;c= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;0RAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,gHAAiHP,EAAKH,IAKtJ,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 785cc42..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 2cf48d2..174ed6a 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-trunc": "^0.1.1", - "@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", @@ -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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6bf21b8 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 8099f2e46bd1f6b4baef5d6d91cd1dfc29f7908c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 06:07:05 +0000 Subject: [PATCH 079/182] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 74611b9..2cf48d2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.1.1", "@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 7becfc24052dc5dacd2e1febc64ba53125e8cc0f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 11:37:06 +0000 Subject: [PATCH 080/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6d658e3..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";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,n,i,a,m,o){var d,l,f,p,u,c;for(d=t.length,l=1,c=0;c=l&&(m=l-1);else if("wrap"===o)m<0?(m+=l)<0&&0!==(m%=l)&&(m+=l):m>=l&&(m-=l)>=l&&(m%=l);else if("normalize"===o&&m<0&&(m+=l),m<0||m>=l)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",l,m));if(f=0,"column-major"===a){for(c=d-1;c>=0;c--)(u=n[c])<0?(m-=(p=r(m/u))*u,p+=t[c]-1):m-=(p=r(m/u))*u,f+=p*s(u);return f}for(c=0;c= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;0RAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,gHAAiHP,EAAKH,IAKtJ,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6bf21b8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From aa0bb382b393a88eaa5d60eeebb2125a8b598c8a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 11:37:22 +0000 Subject: [PATCH 081/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 66 +- src/main.c | 127 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 6202 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/bind2vind.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 a1ba150..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T04:08:04.081Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 aa0ab13..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6d658e3 --- /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";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,n,i,a,m,o){var d,l,f,p,u,c;for(d=t.length,l=1,c=0;c=l&&(m=l-1);else if("wrap"===o)m<0?(m+=l)<0&&0!==(m%=l)&&(m+=l):m>=l&&(m-=l)>=l&&(m%=l);else if("normalize"===o&&m<0&&(m+=l),m<0||m>=l)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",l,m));if(f=0,"column-major"===a){for(c=d-1;c>=0;c--)(u=n[c])<0?(m-=(p=r(m/u))*u,p+=t[c]-1):m-=(p=r(m/u))*u,f+=p*s(u);return f}for(c=0;c= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;0RAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,gHAAiHP,EAAKH,IAKtJ,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 785cc42..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 2cf48d2..174ed6a 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.1.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-trunc": "^0.1.1", - "@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", @@ -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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1964c4d --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 8ecc0217f10e93257972e909f88e987d182d23f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 11:33:53 +0000 Subject: [PATCH 082/182] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a4400b6..42d67f3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.0", "@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 0c3b60df006b4691d76eb7706630c76905d291e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 19:17:23 +0000 Subject: [PATCH 083/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6d658e3..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";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,n,i,a,m,o){var d,l,f,p,u,c;for(d=t.length,l=1,c=0;c=l&&(m=l-1);else if("wrap"===o)m<0?(m+=l)<0&&0!==(m%=l)&&(m+=l):m>=l&&(m-=l)>=l&&(m%=l);else if("normalize"===o&&m<0&&(m+=l),m<0||m>=l)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",l,m));if(f=0,"column-major"===a){for(c=d-1;c>=0;c--)(u=n[c])<0?(m-=(p=r(m/u))*u,p+=t[c]-1):m-=(p=r(m/u))*u,f+=p*s(u);return f}for(c=0;c= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;0RAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,gHAAiHP,EAAKH,IAKtJ,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1964c4d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b257aaefb4b9d12a62aac5b3227985b145cb530f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 19:18:27 +0000 Subject: [PATCH 084/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 66 +- src/main.c | 127 - stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 47 files changed, 6202 insertions(+), 6412 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/bind2vind.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 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 5098bb4..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6d658e3 --- /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";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,n,i,a,m,o){var d,l,f,p,u,c;for(d=t.length,l=1,c=0;c=l&&(m=l-1);else if("wrap"===o)m<0?(m+=l)<0&&0!==(m%=l)&&(m+=l):m>=l&&(m-=l)>=l&&(m%=l);else if("normalize"===o&&m<0&&(m+=l),m<0||m>=l)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",l,m));if(f=0,"column-major"===a){for(c=d-1;c>=0;c--)(u=n[c])<0?(m-=(p=r(m/u))*u,p+=t[c]-1):m-=(p=r(m/u))*u,f+=p*s(u);return f}for(c=0;c= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;0RAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,gHAAiHP,EAAKH,IAKtJ,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 785cc42..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 42d67f3..4b51181 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.0", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.2.0", - "@stdlib/math-base-special-trunc": "^0.2.0", - "@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.2.0" - }, - "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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e40223a --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 104ab08b62437d2a59dd5356635e1e49223beb4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 21:44:18 +0000 Subject: [PATCH 085/182] 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 225377b..bc12379 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.0-esm/index.mjs'; ``` #### bind2vind( 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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.0-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 6671203b7bb0754fbd6c5588eed39a046747c692 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 21:44:19 +0000 Subject: [PATCH 086/182] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bc12379..32c79a9 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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-bind2vind/tags). For example, + ```javascript import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.0-esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 4a951b625260ddf15861783f90e4f22c1bb465c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 21:36:38 +0000 Subject: [PATCH 087/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index b2d2ac2..40421e5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.1", "@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 73476ec356be833dc72c0d1afc37f0b808d83142 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 01:54:00 +0000 Subject: [PATCH 088/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6d658e3..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";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function t(t,n,i,a,m,o){var d,l,f,p,u,c;for(d=t.length,l=1,c=0;c=l&&(m=l-1);else if("wrap"===o)m<0?(m+=l)<0&&0!==(m%=l)&&(m+=l):m>=l&&(m-=l)>=l&&(m%=l);else if("normalize"===o&&m<0&&(m+=l),m<0||m>=l)throw new RangeError(e("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",l,m));if(f=0,"column-major"===a){for(c=d-1;c>=0;c--)(u=n[c])<0?(m-=(p=r(m/u))*u,p+=t[c]-1):m-=(p=r(m/u))*u,f+=p*s(u);return f}for(c=0;c= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;0RAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,gHAAiHP,EAAKH,IAKtJ,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e40223a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 355ce89cb772f2cd5c1272e9f1f3c54176db9e3b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 01:55:35 +0000 Subject: [PATCH 089/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 66 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 47 files changed, 4867 insertions(+), 6406 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/bind2vind.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 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..605bcf3 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.0-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 40421e5..2d7e437 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-trunc": "^0.2.1", - "@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.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.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..42da865 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From fca7b7a6f1eb113d25b0bbb00229838b0e165098 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 04:35:31 +0000 Subject: [PATCH 090/182] 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 3298893..7072b88 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.1-esm/index.mjs'; ``` #### bind2vind( 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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.1-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From ff51bdb6c5117afb0a9025cac5a99e23fb4ee7c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 04:35:31 +0000 Subject: [PATCH 091/182] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7072b88..29c8e08 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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-bind2vind/tags). For example, + ```javascript import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.1-esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 2ca46c0c91c710aa2b5b93fcd231e596975e263b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 05:34:46 +0000 Subject: [PATCH 092/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index fb7339e..2932cf0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.1", "@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 44665e3ff4757434483fe576e28a22cdf0648cfb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 10:29:05 +0000 Subject: [PATCH 093/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 605bcf3..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.0-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 42da865..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 44ac6cc680f06f3d7da6b869f3dafdbc93d40d35 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 10:29:18 +0000 Subject: [PATCH 094/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 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/bind2vind.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 3b525b5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T03:59:48.615Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..422e816 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 2932cf0..2d7e437 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-trunc": "^0.2.1", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fb9718a --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 39513ade1b517d99d15df967530729b02cfd96ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 04:57:15 +0000 Subject: [PATCH 095/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 665ae7c..22b6690 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.1", "@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 7eafa4695213708fc3395d213a02d8c6d6e23493 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 09:50:20 +0000 Subject: [PATCH 096/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 422e816..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fb9718a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6dfdd9138e04ec5f5d7c00132715c26ee44349a1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 09:50:37 +0000 Subject: [PATCH 097/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6412 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/bind2vind.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 90d19fb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T03:18:10.338Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..422e816 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 22b6690..2d7e437 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-trunc": "^0.2.1", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fb9718a --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From df2fd24fbf7bac7122b20ffbfeb9c4470a12bd9f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 01:14:52 +0000 Subject: [PATCH 098/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 665ae7c..22b6690 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.1", "@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 790af9a3c039d1037fd70efbd9558f884e5d181e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 06:28:09 +0000 Subject: [PATCH 099/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 422e816..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fb9718a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 23d54a270d65bfcf7190afd65fe0753640851d58 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 06:28:28 +0000 Subject: [PATCH 100/182] 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 47 files changed, 4867 insertions(+), 6413 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/bind2vind.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 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..422e816 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 22b6690..2d7e437 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.1", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-trunc": "^0.2.1", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fb9718a --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From c7b5d8033536891b6efa5a0e6abb1708f602680c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 02:58:46 +0000 Subject: [PATCH 101/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 7fefb77..0428a21 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.1", "@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 aff2b56e3dfce1c4b9e03deb7f475dd8cdada5e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 03:30:38 +0000 Subject: [PATCH 102/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 422e816..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fb9718a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 20f4878e507e1c66925c14a0ff9529dc3a9766b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 03:31:00 +0000 Subject: [PATCH 103/182] 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 | 187 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 47 files changed, 4867 insertions(+), 6606 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/bind2vind.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 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 55eac1f..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 `bind2vind`. -*/ -#include "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9ec5539 --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 0428a21..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-trunc": "^0.2.1", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ee32ac6 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 12e38619065d1198bde1e761baea554dcf4a6304 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 03:37:53 +0000 Subject: [PATCH 104/182] 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 be51793..8019002 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.2-esm/index.mjs'; ``` #### bind2vind( 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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.2-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From 4731218cddfa4c3f3fc96d066638c4f897867ed2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 03:37:54 +0000 Subject: [PATCH 105/182] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8019002..cc81483 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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-bind2vind/tags). For example, + ```javascript import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.2-esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From f50874ef71370acfc32f61fd8d734bd51768a64c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 05:34:55 +0000 Subject: [PATCH 106/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 2c0e026..3a3ee1a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.2", "@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 35f5a111c75a5440d3c3a369e1267ae98fd0e132 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 10:06:03 +0000 Subject: [PATCH 107/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9ec5539..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ee32ac6..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 306549f5071b011eba238bf83a76a8bd63051db5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 10:06:17 +0000 Subject: [PATCH 108/182] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 138 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6557 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/bind2vind.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 49062b1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T04:01:44.032Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..03b158d --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 3a3ee1a..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0bb716f --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 1a493a9cd9032ae5ca24bcc9c4a6079694f7ae35 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 20:42:15 +0000 Subject: [PATCH 109/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 2c0e026..3a3ee1a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.2", "@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 59176d92cd296c3fbb0715d91adeee4b224963e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 23:58:31 +0000 Subject: [PATCH 110/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 03b158d..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0bb716f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 22b0bb8d43a3d1b2e99e36da9404a8973413bc2a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 23:58:50 +0000 Subject: [PATCH 111/182] 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 | 211 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6630 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/bind2vind.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 3aa7e03..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T19:20:15.320Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..03b158d --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 3a3ee1a..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0bb716f --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From dbd433260b7271aaea25e2aa00b97f69c69cf048 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 05:45:38 +0000 Subject: [PATCH 112/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index ff530aa..1cbc34e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.2", "@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 061d025a5e9a3806f9dab1d6ebda1902d4c5e833 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 10:00:43 +0000 Subject: [PATCH 113/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 03b158d..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0bb716f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bcd730f4a6dd52f82068993623528a651974e52c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 10:00:59 +0000 Subject: [PATCH 114/182] 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 | 210 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6629 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/bind2vind.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 e170e5b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T04:17:02.172Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..03b158d --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 1cbc34e..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0bb716f --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 0d2b52ce782bd1edcbbc662605056168d2e82940 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 06:00:51 +0000 Subject: [PATCH 115/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index ff530aa..1cbc34e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.2", "@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 42bd8a3dc7effffeeb8dcc9bbb5afb82c380cae8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 10:28:51 +0000 Subject: [PATCH 116/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 03b158d..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0bb716f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7f39f9ea0c5ab668bf5b71bf911fe113f459b9ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 10:29:03 +0000 Subject: [PATCH 117/182] 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 | 210 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6629 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/bind2vind.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 5c33a98..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T04:28:10.023Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..03b158d --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 1cbc34e..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0bb716f --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 2c64bdc2ef2950e03c17388e24ace9171af38c69 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 05:55:07 +0000 Subject: [PATCH 118/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index ff530aa..1cbc34e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.2", "@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 15f12cfcd336cccfe1bb663954ba43713782d666 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 09:42:41 +0000 Subject: [PATCH 119/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 03b158d..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0bb716f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 40d413f329b1483724c4e171083358c77e633db1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 09:42:54 +0000 Subject: [PATCH 120/182] 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 | 210 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6629 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/bind2vind.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 f8cdd0e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T04:31:48.538Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..03b158d --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 1cbc34e..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0bb716f --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 5d5d2debe3da904f8be4b8c404ea39a875bdb3e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 06:08:52 +0000 Subject: [PATCH 121/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 79a89f7..705ed61 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.2", "@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 d2c1760873203e80222c6f3fb256773ae51e1978 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 10:10:28 +0000 Subject: [PATCH 122/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 03b158d..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0bb716f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 33a4397cf518781105ee42eaeadc7974b0b090c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 10:10:41 +0000 Subject: [PATCH 123/182] 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 | 210 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6734 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/bind2vind.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 f81c912..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T04:37:21.270Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3df874c..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..03b158d --- /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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 705ed61..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0bb716f --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 2f98b88b32285d6184787f0c60db8e7758d19ad6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 01:09:43 +0000 Subject: [PATCH 124/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 79a89f7..705ed61 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.2", "@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 d36290f2793d5fb427c34df841bd0328e2dcf62f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 02:02:23 +0000 Subject: [PATCH 125/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 03b158d..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";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0bb716f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6b3c38660f8c66fe5a8d6e998ef97b10b0eb3879 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 02:02:38 +0000 Subject: [PATCH 126/182] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 210 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6737 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/bind2vind.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/.keepalive b/.github/.keepalive deleted file mode 100644 index ba7574d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-17T01:05:41.167Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc5084e --- /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/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 705ed61..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0bb716f --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From a32b00530e117fac581d0c2053c197eaa2281533 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 01:11:47 +0000 Subject: [PATCH 127/182] 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 785cc42..da35a72 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' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); @@ -88,7 +88,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 79a89f7..705ed61 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/math-base-special-trunc": "^0.2.2", "@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 f83e93640dcb88192f75a5359ce089349cb4965a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 01:34:15 +0000 Subject: [PATCH 128/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc5084e..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/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0bb716f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bd5abfa3952e427a983760d1e2dd4f2a6cc78ae2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 01:34:31 +0000 Subject: [PATCH 129/182] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 210 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 130 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6737 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/bind2vind.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/.keepalive b/.github/.keepalive deleted file mode 100644 index aacea0d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-24T01:04:57.819Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7c44b17..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){ -var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc5084e --- /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/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index da35a72..0000000 --- a/lib/main.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order === 'column-major' ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 705ed61..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -96,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0bb716f --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 9d0bc3ad0b00c462f9f0d7f185d4580381bc73ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:52:58 +0000 Subject: [PATCH 130/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index c955cc8..1ed33b1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,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 e3135df99afae19b2f88218dd73269bf440ce56c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:53:16 +0000 Subject: [PATCH 131/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc5084e..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/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function t(t,i,m,o,n,l){var a,d,f,p,h,j;for(a=t.length,d=1,j=0;j=d&&(n=d-1);else if("wrap"===l)n<0?(n+=d)<0&&0!==(n%=d)&&(n+=d):n>=d&&(n-=d)>=d&&(n%=d);else if("normalize"===l&&n<0&&(n+=d),n<0||n>=d)throw new RangeError(r("0i35E",d,n));if(f=0,"column-major"===o){for(j=a-1;j>=0;j--)(h=i[j])<0?(n-=(p=e(n/h))*h,p+=t[j]-1):n-=(p=e(n/h))*h,f+=p*s(h);return f}for(j=0;j= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","trunc","abs"],"mappings":";;mSAmDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACS,iBAAVL,EAA2B,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIM,EAAOX,EAAIM,IACJA,EAEZF,GAAOC,EAAIO,EAAKN,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0bb716f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b51bef412e6e093d2cceb2a175cc92a7f2e699d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:53:32 +0000 Subject: [PATCH 132/182] 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 | 244 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 68 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6772 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/bind2vind.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 ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..990966f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 1ed33b1..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -97,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8e701c8 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From ebc88b5b944ec6df31f44136102e3e6b1e27d31b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 01:53:52 +0000 Subject: [PATCH 133/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index c955cc8..1ed33b1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,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 074bff178dbb13fca9b2fadc1f991e97c5540316 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 02:20:27 +0000 Subject: [PATCH 134/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 990966f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8e701c8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1b620e864708830953e1e52e43183f979c5b0c50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 02:20:43 +0000 Subject: [PATCH 135/182] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 244 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 68 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6773 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/bind2vind.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 743711b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-26T01:27:37.918Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..990966f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 1ed33b1..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -97,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8e701c8 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 542f130ceab0ec84310738a6bc5428cae77ba937 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 01:47:18 +0000 Subject: [PATCH 136/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index c955cc8..1ed33b1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,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 1b3c02318503257d6cf8a71f9ebbbcba991a9145 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:36:34 +0000 Subject: [PATCH 137/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 990966f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8e701c8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1d95255799464940052b0540ae328814d5a62917 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:36:54 +0000 Subject: [PATCH 138/182] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 244 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 68 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6773 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/bind2vind.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 8a26618..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-30T01:28:36.077Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..990966f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; 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 1ed33b1..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -97,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8e701c8 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 651e1b94d01e8ebfe9112c78c1140b8d5cd20981 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 18 Aug 2025 00:37:26 +0000 Subject: [PATCH 139/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index c955cc8..1ed33b1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,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 41a3ee57e4fd77999ccf12d289cc0b3b3d1d874c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 18 Aug 2025 00:38:16 +0000 Subject: [PATCH 140/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 990966f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8e701c8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9efd80d9afbaa1e3b9b44bb959ce7578444273a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 18 Aug 2025 00:38:34 +0000 Subject: [PATCH 141/182] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 246 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 68 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6775 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/bind2vind.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 39d3c73..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-08-18T00:36:54.549Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 6abc862..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..990966f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 1ed33b1..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -97,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8e701c8 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 26ab3f92f737a9b0789328e4188b7d021bad9b35 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Oct 2025 01:02:34 +0000 Subject: [PATCH 142/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index c955cc8..1ed33b1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,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 e31516d8824498e679182f82e1ad20699cea7273 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Oct 2025 01:03:17 +0000 Subject: [PATCH 143/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 990966f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8e701c8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b1d0bfbbf1f75517c3067767045ea421d5e63ec7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Oct 2025 01:03:46 +0000 Subject: [PATCH 144/182] 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 | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 260 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 68 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6793 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/bind2vind.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 ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..990966f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 1ed33b1..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -97,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8e701c8 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From f05d364472f8016269fa93b01ec3df7ff7f8728d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 22 Dec 2025 00:36:35 +0000 Subject: [PATCH 145/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index c955cc8..1ed33b1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,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 9c601c63bd40c3b8f6e6252a8fe65019a08ac050 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 22 Dec 2025 00:37:19 +0000 Subject: [PATCH 146/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 990966f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8e701c8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 67b660f5fa87a507ae16aca9bc476573220ac9da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 22 Dec 2025 00:37:38 +0000 Subject: [PATCH 147/182] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 260 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 68 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6794 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/bind2vind.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 964a9d7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-12-22T00:36:04.881Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..990966f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 1ed33b1..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@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", @@ -97,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 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8e701c8 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 76fbcde1212d385d65ae1839816a6d387dac251e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Jan 2026 05:53:42 +0000 Subject: [PATCH 148/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index ab4885c..db8b858 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.0", "@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.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 9404920c07fc9dc84ef2f97370589c0d3297df66 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Jan 2026 05:57:07 +0000 Subject: [PATCH 149/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 990966f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;iZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8e701c8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e8ff4610b5071ad9989fdfd31f8bf92195ef9774 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Jan 2026 05:57:33 +0000 Subject: [PATCH 150/182] 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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 260 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6892 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/bind2vind.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 ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..91afdd2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 db8b858..bd5df34 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.2", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.0", - "@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.3", - "@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", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1bcf1d4 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From ef4e2966cf1cb0f85b7baa3861dd304ad4a3cbbf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Feb 2026 15:52:02 +0000 Subject: [PATCH 151/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 4517310..7ed6ce1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.0", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From e92a772555f4463d9ef9bd69e5d7f694df0ac61a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Feb 2026 15:57:59 +0000 Subject: [PATCH 152/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 91afdd2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1bcf1d4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 871ba6ef61d5f40cc30566d849bced9450daff35 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Feb 2026 15:58:16 +0000 Subject: [PATCH 153/182] 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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 260 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6885 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/bind2vind.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 ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a7519fa --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 7ed6ce1..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.3", - "@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.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9da397 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 74decbce36ef1ffd11d3b0c7d6dced444cd18525 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Feb 2026 16:00:22 +0000 Subject: [PATCH 154/182] Update README.md for ESM bundle v0.2.3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b16bbf..5d6f94c 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.3-esm/index.mjs'; ``` #### bind2vind( 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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.3-esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From e86be16a67c10554eb034003de39f7a077d45326 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Feb 2026 16:00:23 +0000 Subject: [PATCH 155/182] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d6f94c..e46cde0 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@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-bind2vind/tags). For example, + ```javascript import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.3-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 bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@v0.2.3-esm/index.mjs'; +import bind2vind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bind2vind@esm/index.mjs'; // Specify array meta data: var shape = [ 3, 3, 3 ]; From fa84494a2fbdabd34aa9ff0432e9a21e7934da81 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 01:18:22 +0000 Subject: [PATCH 156/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 37bfc80..58b8989 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From d4c3fc62e1cfd883e243ec28a456f400cb483e2d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 01:43:29 +0000 Subject: [PATCH 157/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a7519fa..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9da397..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 46fc0483de6671cd7f91aa27363c223c7eb8cb51 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 01:43:45 +0000 Subject: [PATCH 158/182] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 260 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6886 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/bind2vind.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 44fc1d1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-02-09T01:13:15.269Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 58b8989..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From bc19a13b783cf298d7b7383b0feccd1cb4379f17 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Mar 2026 03:23:52 +0000 Subject: [PATCH 159/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 37bfc80..58b8989 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 6d9e065e15ede58d3d6156648056cdf4913e6227 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Mar 2026 05:05:50 +0000 Subject: [PATCH 160/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5aa2769..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 75a5bd0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 44e45028399da1622170e754326ea833ff7fabfd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Mar 2026 05:06:10 +0000 Subject: [PATCH 161/182] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 260 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6886 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/bind2vind.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 072544b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-03-16T02:27:12.676Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 58b8989..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From acc311943be2814270153091c87ea194e6c0ec2b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Mar 2026 03:16:19 +0000 Subject: [PATCH 162/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 37bfc80..58b8989 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From ad81a3de5ea088d923360c072aeb77bad4367cb4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Mar 2026 04:59:47 +0000 Subject: [PATCH 163/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5aa2769..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 75a5bd0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6a76954bb848426521fa98cf005c0ad6d06f2ebe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Mar 2026 05:00:12 +0000 Subject: [PATCH 164/182] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 260 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6897 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/bind2vind.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 29b8765..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-03-23T02:33:22.366Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 58b8989..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From e6d681824c82b28ef48967bfa75152cef65282a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 14 Apr 2026 03:24:52 +0000 Subject: [PATCH 165/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 37bfc80..58b8989 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 5294efa117f31990e9c53e6dfd3624789b2bec36 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 14 Apr 2026 03:37:08 +0000 Subject: [PATCH 166/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5aa2769..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 75a5bd0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2f4eaf12e4a812841af9e2fc9c1d0d42cbaf2e83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 14 Apr 2026 03:37:28 +0000 Subject: [PATCH 167/182] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 260 - 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6897 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/bind2vind.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a20b2ea..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-04-14T03:20:45.586Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 6b2e4fe..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 bind2vind = 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 58b8989..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From c387ee8e73ae8f8b8464a84e54d70ce0bc76e83b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 07:51:52 +0000 Subject: [PATCH 168/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 37bfc80..58b8989 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 71168ac51647b15a897ed5924cb76fd5c5e1e113 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 07:54:22 +0000 Subject: [PATCH 169/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5aa2769..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 75a5bd0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c9ff3384c5298ee2c50f812dc12b8c2091a24e6d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 07:54:43 +0000 Subject: [PATCH 170/182] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 294 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 555 -- 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6949 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/bind2vind.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 ce84454..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,555 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var bind2vind = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:mode=throw,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 58b8989..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 792a5193694dbd434ac32be31cad674ff23a413e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 26 May 2026 03:31:47 +0000 Subject: [PATCH 171/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index 37bfc80..58b8989 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From cc43bcd10e4c19ae8321405be9849637a26711e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 26 May 2026 03:46:55 +0000 Subject: [PATCH 172/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5aa2769..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 75a5bd0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 091dd66ca58030eaeea3c47744e029cda8bde409 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 26 May 2026 03:47:14 +0000 Subject: [PATCH 173/182] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 294 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 555 -- 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6950 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/bind2vind.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1e9f5b2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-26T03:26:39.586Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 ce84454..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,555 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var bind2vind = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:mode=throw,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ec71b9f..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=b(function(z,m){ -var g=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),i=require('@stdlib/math-base-special-abs/dist'),w=require('@stdlib/error-tools-fmtprodmsg/dist');function y(u,t,k,q,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(w('0i35E',e,r));if(s=0,g(q)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*i(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 58b8989..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 85be456fd3955e04c1d16a96887370862d48129f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 6 Jul 2026 03:30:20 +0000 Subject: [PATCH 174/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index f13d89d..1eb36e2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 8170a35af7fa073524cf52dfe7a5f18db479224e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 6 Jul 2026 03:43:40 +0000 Subject: [PATCH 175/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5aa2769..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 75a5bd0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5a2c1accded1fa90f55680bde49ce6ed333d6fed Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 6 Jul 2026 03:44:01 +0000 Subject: [PATCH 176/182] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 294 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 555 -- 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6950 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/bind2vind.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3741425..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-07-06T03:26:08.965Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 ce84454..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,555 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var bind2vind = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:mode=throw,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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 a1b9c39..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 83606ae..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(u,t){return function(){try{return t||u((t={exports:{}}).exports,t),t.exports}catch(i){throw (t=0, i)}};};var q=g(function(z,c){ -var w=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist');function j(u,t,i,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(y('0i35E',e,r));if(s=0,w(b)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 1eb36e2..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 464dd0ef9884c06098976a345787b852fba96548 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Aug 2026 00:43:42 +0000 Subject: [PATCH 177/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index f13d89d..1eb36e2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From adc0c300641ba727407dfdbf2532ee72e0167ea4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Aug 2026 00:57:42 +0000 Subject: [PATCH 178/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5aa2769..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 75a5bd0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f0c8af2a761ff1ced5613211604dac0afa2d848f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Aug 2026 00:58:01 +0000 Subject: [PATCH 179/182] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 296 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 555 -- 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 48 files changed, 4867 insertions(+), 6951 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/bind2vind.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 ce84454..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,555 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var bind2vind = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:mode=throw,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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 3507585..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 83606ae..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(u,t){return function(){try{return t||u((t={exports:{}}).exports,t),t.exports}catch(i){throw (t=0, i)}};};var q=g(function(z,c){ -var w=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist');function j(u,t,i,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(y('0i35E',e,r));if(s=0,w(b)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 1eb36e2..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -}); From 37c3dcee9e79fb515328bcaa3f8c1bebc6c5a639 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Aug 2026 02:48:45 +0000 Subject: [PATCH 180/182] 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 ff57d29..22811ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); var trunc = require( '@stdlib/math-base-special-trunc' ); var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -89,7 +89,7 @@ function bind2vind( 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( '0i35E', len, idx ) ); } } // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... diff --git a/package.json b/package.json index f13d89d..1eb36e2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", "@stdlib/ndarray-index-modes": "^0.2.3", "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-library-manifest": "^0.2.4", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 5e2ec9613af1d2ee7fa1a9e9597ab92d6cfefee4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Aug 2026 02:58:19 +0000 Subject: [PATCH 181/182] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 37e0d1c..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Mode, Order } from '@stdlib/types/ndarray'; - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -declare function bind2vind( shape: ArrayLike, strides: ArrayLike, offset: number, order: Order, idx: number, mode: Mode ): number; - - -// EXPORTS // - -export = bind2vind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5aa2769..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 75a5bd0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fb7c9b6700f22409ed96d10050bca1341a06422b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Aug 2026 02:58:40 +0000 Subject: [PATCH 182/182] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 205 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 296 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 555 -- 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 | 150 - examples/index.js | 56 - include/stdlib/ndarray/base/bind2vind.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 | 131 - manifest.json | 41 - package.json | 67 +- src/main.c | 127 - stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 939 ---- 49 files changed, 4867 insertions(+), 6953 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/bind2vind.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 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7352b86..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-24T02:44:37.991Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ed98820..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/bind2vind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 f35741e..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/bind2vind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 2de7dc6..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: '3 3 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 ce84454..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,555 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var bind2vind = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:mode=throw,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=throw,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=wrap,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=clamp,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=row-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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( format( '%s:mode=normalize,offset=0,order=column-major', pkg ), function benchmark( b ) { - var strides; - var 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 = bind2vind( 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 3507585..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 "stdlib/ndarray/base/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "bind2vind" -#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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( rand_double()*len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, -10, 1 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, -10, 100 }; - const int64_t offset = 90; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 100, 10, 1 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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; - - const int64_t ndims = 3; - const int64_t shape[] = { 10, 10, 10 }; - const int64_t strides[] = { 1, 10, 100 }; - const int64_t offset = 0; - const int64_t len = 1000; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*len*2.0)-len ); - ind = stdlib_ndarray_bind2vind( 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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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::%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 5dae0c9..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/bind2vind" -%% click B href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/bind2vind -[production-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/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 c2aea12..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import bind2vind from '../docs/types/index'; -export = bind2vind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 83606ae..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(u,t){return function(){try{return t||u((t={exports:{}}).exports,t),t.exports}catch(i){throw (t=0, i)}};};var q=g(function(z,c){ -var w=require('@stdlib/ndarray-base-assert-is-column-major-string/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist');function j(u,t,i,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(y('0i35E',e,r));if(s=0,w(b)){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a= 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\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 = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oDAAqD,EAC9EC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,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,EAAM,EACDb,EAAeQ,CAAM,EAAI,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIb,EAAOQ,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIZ,EAAKa,CAAE,EAEnB,OAAOF,CACR,CAKAd,EAAO,QAAUK,IC1FjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isColumnMajor", "trunc", "abs", "format", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ddb1b27..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,50 +0,0 @@ - -{{alias}}( shape, strides, offset, order, idx, mode ) - Converts a linear index in an underlying data buffer to a linear index in an - array view. - - 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 underlying data buffer. - - 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 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 array view. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, -3, 1 ]; - > var o = 6; - > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' ) - 1 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fa58bc5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bind2vind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, idx, 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 = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError - bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError - bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError - bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError - bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError - bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError - bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const order = 'row-major'; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError - bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError - bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError - bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a known array order... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const idx = 17; - const mode = 'throw'; - bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError - bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const mode = 'throw'; - bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError - bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError - bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError - bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError - bind2vind( 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 known mode... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError - bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 6, 1 ]; - const offset = 0; - const order = 'row-major'; - const idx = 17; - bind2vind(); // $ExpectError - bind2vind( shape ); // $ExpectError - bind2vind( shape, strides ); // $ExpectError - bind2vind( shape, strides, offset ); // $ExpectError - bind2vind( shape, strides, offset, order ); // $ExpectError - bind2vind( shape, strides, offset, order, idx ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index c1f4072..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 bind2vind = 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 underlying data buffer index, determine the corresponding index into an array view... -var ind; -for ( i = 0; i < len; i++ ) { - ind = bind2vind( shape, strides, offset, order, i, 'throw' ); - console.log( 'buffer[%d] => view[%d]', i, ind ); -} diff --git a/include/stdlib/ndarray/base/bind2vind.h b/include/stdlib/ndarray/base/bind2vind.h deleted file mode 100644 index b1ffe95..0000000 --- a/include/stdlib/ndarray/base/bind2vind.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_BIND2VIND_H -#define STDLIB_NDARRAY_BASE_BIND2VIND_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 underlying data buffer to a linear index in an array view. -*/ -int64_t stdlib_ndarray_bind2vind( 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_BIND2VIND_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 f1c0251..37e0d1c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// /// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5aa2769 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-trunc@v0.2.3-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";function i(i,m,n,o,a,d){var l,f,p,j,h,c;for(l=i.length,f=1,c=0;c=f&&(a=f-1);else if("wrap"===d)a<0?(a+=f)<0&&0!==(a%=f)&&(a+=f):a>=f&&(a-=f)>=f&&(a%=f);else if("normalize"===d&&a<0&&(a+=f),a<0||a>=f)throw new RangeError(t("0i35E",f,a));if(p=0,s(o)){for(c=l-1;c>=0;c--)(h=m[c])<0?(a-=(j=r(a/h))*h,j+=i[c]-1):a-=(j=r(a/h))*h,p+=j*e(h);return p}for(c=0;c= 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( '0i35E', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( isColumnMajor( order ) ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nexport default bind2vind;\n"],"names":["bind2vind","shape","strides","offset","order","idx","mode","ndims","len","ind","k","s","i","length","RangeError","format","isColumnMajor","trunc","abs"],"mappings":";;wZAoDA,SAASA,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,GACvD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAMY,OACdL,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,GAEf,GAAc,UAATN,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,IAAIM,WAAYC,EAAQ,QAASP,EAAKH,IAK9C,GADAI,EAAM,EACDO,EAAeZ,GAAU,CAC7B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,KAC1BD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACP,CAED,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,KACvBD,EAAIT,EAASU,IACJ,GAERP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EACXD,GAAKT,EAAOW,GAAM,GAGlBP,IADAK,EAAIO,EAAOZ,EAAIM,IACJA,EAEZF,GAAOC,EAAIQ,EAAKP,GAEjB,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f15aa73..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 underlying data buffer to a linear index in an array view. -* -* @module @stdlib/ndarray-base-bind2vind -* -* @example -* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' ); -* -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ - -// MODULES // - -var bind2vind = require( './main.js' ); - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 22811ae..0000000 --- a/lib/main.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 trunc = require( '@stdlib/math-base-special-trunc' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* @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 underlying data buffer -* @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 array view -* -* @example -* var shape = [ 3, 3 ]; -* var strides = [ -3, 1 ]; -* var offset = 6; -* var order = 'row-major'; -* var mode = 'throw'; -* -* var ind = bind2vind( shape, strides, offset, order, 7, mode ); -* // returns 1 -*/ -function bind2vind( shape, strides, offset, order, idx, mode ) { - var ndims; - var len; - var ind; - var k; - 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( '0i35E', len, idx ) ); - } - } - // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( isColumnMajor( order ) ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = trunc( idx/s ); - idx -= k * s; - k += shape[ i ] - 1; - } else { - k = trunc( idx/s ); - idx -= k * s; - } - ind += k * abs( s ); - } - return ind; -} - - -// EXPORTS // - -module.exports = bind2vind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index af9e040..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 1eb36e2..0556355 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.3", "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/math-base-special-abs": "^0.2.3", - "@stdlib/math-base-special-trunc": "^0.2.3", - "@stdlib/ndarray-base-assert-is-column-major-string": "^0.1.1", - "@stdlib/ndarray-index-modes": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-library-manifest": "^0.2.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-base-strides2offset": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 920ca8f..0000000 --- a/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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/bind2vind.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -/** -* Converts a linear index in an underlying data buffer to a linear index in an array view. -* -* ## 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/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bind2vind.h" -* -* int64_t ndims = 2; -* int64_t shape[] = { 3, 3 }; -* int64_t strides[] = { -3, 1 }; -* int64_t offset = 6; -* -* int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR ); -* // returns 1 -*/ -int64_t stdlib_ndarray_bind2vind( 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 k; - 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 buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)... - ind = 0; - if ( order == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = ndims-1; i >= 0; i-- ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; - } - // Case: row-major - for ( i = 0; i < ndims; i++ ) { - s = strides[ i ]; - if ( s < 0 ) { - k = index / s; // truncates - index -= k * s; - k += shape[ i ] - 1; - } else { - k = index / s; // cppcheck-suppress zerodivcond // truncates - index -= k * s; - } - ind += k * llabs( s ); - } - return ind; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..75a5bd0 --- /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 1de0ef0..0000000 --- a/test/test.js +++ /dev/null @@ -1,939 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var bind2vind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bind2vind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'throw' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'throw' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'throw' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'throw' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( 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() { - bind2vind( 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() { - bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 1, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 4, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 5, 'wrap' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -6, 'wrap' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -9, 'wrap' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'wrap' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( 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 = bind2vind( shape, strides, offset, order, 4, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 0, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -8, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'clamp' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 15, 'clamp' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=row-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the mode is `normalize`, the function normalizes indices before converting a linear index in an underlying data buffer to a linear index in an array view (order=column-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 = bind2vind( shape, strides, offset, order, 0, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 1, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, 3, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -4, 'normalize' ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -3, 'normalize' ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -2, 'normalize' ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = bind2vind( shape, strides, offset, order, -1, 'normalize' ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( 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() { - bind2vind( shape, strides, offset, order, 999999, 'normalize' ); - } - - function bar() { - bind2vind( shape, strides, offset, order, -999999, 'normalize' ); - } -});